Created
June 9, 2011 05:42
-
-
Save hisaichi5518/1016126 to your computer and use it in GitHub Desktop.
eachとspliceの速さ比較用コード
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 warnings; | |
use Benchmark qw(:all); | |
print "splice(), each(), keys(), values() Benchmark!!\n"; | |
my %mapping = my @mapping = map {$_ => $_} (1..100); | |
cmpthese -1, { | |
splice => sub { | |
while (my ($key, $value) = splice @mapping, 0, 2) {} | |
}, | |
each => sub { | |
while (my ($key, $value) = each %mapping) {} | |
}, | |
keys => sub { | |
for my $k (keys %mapping) { | |
my $value = $mapping{$k}; | |
} | |
}, | |
values => sub { | |
for my $v (values %mapping) {} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment