Skip to content

Instantly share code, notes, and snippets.

@fujiwara
Created June 7, 2010 14:49
Show Gist options
  • Save fujiwara/428752 to your computer and use it in GitHub Desktop.
Save fujiwara/428752 to your computer and use it in GitHub Desktop.
use strict;
use Benchmark qw/cmpthese/;
cmpthese( 0, {
'core' => \&core_reverse,
'push_pop' => \&push_pop_style,
'slice' => \&slice,
});
sub core_reverse {
my @array1 = (1..10);
@array1 = reverse @array1;
}
sub push_pop_style {
my @array1 = (1..10);
my @array2 = ();
push @array2, pop(@array1) while (@array1);
}
sub slice {
my @array1 = (1..10);
@array1 = @array1[ reverse 0 .. @array1 - 1 ];
}
__END__
Rate push_pop slice core
push_pop 132330/s -- -10% -32%
slice 147332/s 11% -- -24%
core 194014/s 47% 32% --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment