Created
June 7, 2010 14:58
-
-
Save hidekiy/428768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use Benchmark qw/cmpthese/; | |
cmpthese( -1, { | |
'core1' => \&core_reverse1, | |
'core2' => \&core_reverse2, | |
'push_pop' => \&push_pop_style, | |
'pre_reverse' => \&pre_reverse, | |
}); | |
sub core_reverse1 { | |
my @array1 = (1..10); | |
@array1 = reverse @array1; | |
} | |
sub core_reverse2 { | |
my @array1 = (1..10); | |
my @array2 = (); | |
@array2 = reverse @array1; | |
} | |
sub push_pop_style { | |
my @array1 = (1..10); | |
my @array2 = (); | |
push @array2, pop(@array1) while (@array1); | |
} | |
BEGIN { | |
my @rev_table = reverse 0..9; | |
sub pre_reverse { | |
my @array1 = (1..10); | |
my @array2 = (); | |
@array2 = @array1[@rev_table]; | |
} | |
} | |
__END__ | |
Rate push_pop core1 pre_reverse core2 | |
push_pop 297890/s -- -35% -38% -45% | |
core1 455111/s 53% -- -5% -17% | |
pre_reverse 481208/s 62% 6% -- -12% | |
core2 546132/s 83% 20% 13% -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rev_tableに値入ってないw
rev:314625 でなおした