Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- role EXR { method foo { } };
- class EX { method foo { } };
- role XR {
- has Int @!x;
- method TWEAK { @!x = Nil xx 100; }
- method set($i, $v) { @!x[$i] = $v; }
- };
- class X {
- has $!cap is built;
- has Int @!x;
- method TWEAK { @!x = Nil xx $!cap }
- method set($i, $v) { @!x[$i] = $v; }
- }
- sub exr { my EXR $x .= new; for ^1_000_000 { $x.foo } }
- sub ex { my EX $x .= new; for ^1_000_000 { $x.foo } }
- sub xr { my XR $x .= new(); for ^1_000_000 { $x.set(0, $_) } }
- sub x { my X $x .= new(cap => 100); for ^1_000_000 { $x.set(0, $_) } }
- use Bench;
- for (|(10 xx 5), 500) -> $iters { # warmup
- my $b = Bench.new;
- $b.cmpthese($iters, { :&xr, :&x, :&ex, :&exr });
- }
Advertisement
Add Comment
Please, Sign In to add comment