Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. use strict;
  2.  
  3. use Dumbbench;
  4.  
  5. my $bench = Dumbbench->new( inital_runs => 1000 );
  6.  
  7. my $nums = [ map { int rand(100000000) } 1...1000 ];
  8.  
  9. $bench->add_instances(
  10. Dumbbench::Instance::PerlSub->new(
  11. name => "listassign",
  12. code => sub {
  13. my $num2 = [ @$nums ];
  14.  
  15. @$num2 = sort { $b <=> $a } @$num2;
  16.  
  17. return;
  18. }
  19. ),
  20. Dumbbench::Instance::PerlSub->new(
  21. name => "scalarassign + ArrayRef",
  22. code => sub {
  23. my $num2 = [ @$nums ];
  24.  
  25. $num2 = [sort { $b <=> $a } @$num2];
  26.  
  27. return;
  28. }
  29. ),
  30. );
  31.  
  32. $bench->run;
  33. $bench->report;
  34.  
  35. __END__
  36.  
  37. > perl bench.pl
  38. listassign: Ran 25 iterations (3 outliers).
  39. listassign: Rounded run time per iteration: 1.39103514e-04 +/- 4.6e-11 (0.0%)
  40. scalarassign + ArrayRef: Ran 23 iterations (1 outliers).
  41. scalarassign + ArrayRef: Rounded run time per iteration: 1.16248e-04 +/- 5.1e-08 (0.0%)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement