Guest User

Untitled

a guest
Jul 4th, 2026
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.67 KB | None | 0 0
  1. role EXR { method foo { } };
  2. class EX { method foo { } };
  3.  
  4. role XR {
  5.   has Int @!x;
  6.   method TWEAK { @!x = Nil xx 100; }
  7.   method set($i, $v) { @!x[$i] = $v; }
  8. };
  9.  
  10. class X {
  11.   has $!cap is built;
  12.   has Int @!x;
  13.   method TWEAK { @!x = Nil xx $!cap }
  14.   method set($i, $v) { @!x[$i] = $v; }
  15. }
  16.  
  17. sub exr { my EXR $x .= new; for ^1_000_000 { $x.foo } }
  18. sub ex { my EX $x .= new; for ^1_000_000 { $x.foo } }
  19. sub xr { my XR $x .= new(); for ^1_000_000 { $x.set(0, $_) } }
  20. sub x { my X $x .= new(cap => 100); for ^1_000_000 { $x.set(0, $_) } }
  21.  
  22. use Bench;
  23. for (|(10 xx 5), 500) -> $iters { # warmup
  24.   my $b = Bench.new;
  25.   $b.cmpthese($iters, { :&xr, :&x, :&ex, :&exr });
  26. }
Advertisement
Add Comment
Please, Sign In to add comment