Skip to content

Instantly share code, notes, and snippets.

@hisaichi5518
Created June 9, 2011 05:42
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 hisaichi5518/1016126 to your computer and use it in GitHub Desktop.
Save hisaichi5518/1016126 to your computer and use it in GitHub Desktop.
eachとspliceの速さ比較用コード
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