Created
June 7, 2010 14:49
-
-
Save fujiwara/428752 to your computer and use it in GitHub Desktop.
This file contains hidden or 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( 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