Skip to content

Instantly share code, notes, and snippets.

@gugod
Created April 16, 2019 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gugod/33c0a2ac356021fec768e562be783d46 to your computer and use it in GitHub Desktop.
Save gugod/33c0a2ac356021fec768e562be783d46 to your computer and use it in GitHub Desktop.
use strict;
use Dumbbench;
my $bench = Dumbbench->new( inital_runs => 1000 );
my $nums = [ map { int rand(100000000) } 1...1000 ];
$bench->add_instances(
Dumbbench::Instance::PerlSub->new(
name => "listassign",
code => sub {
my $num2 = [ @$nums ];
@$num2 = sort { $b <=> $a } @$num2;
return;
}
),
Dumbbench::Instance::PerlSub->new(
name => "scalarassign + ArrayRef",
code => sub {
my $num2 = [ @$nums ];
$num2 = [sort { $b <=> $a } @$num2];
return;
}
),
);
$bench->run;
$bench->report;
__END__
> perl bench.pl
listassign: Ran 25 iterations (3 outliers).
listassign: Rounded run time per iteration: 1.39103514e-04 +/- 4.6e-11 (0.0%)
scalarassign + ArrayRef: Ran 23 iterations (1 outliers).
scalarassign + ArrayRef: Rounded run time per iteration: 1.16248e-04 +/- 5.1e-08 (0.0%)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment