use strict; use warnings; use Benchmark qw/ cmpthese /;; for my $count ( 100, 1_000, 10_000, 100_000 ) { my @a = map { log } 2 .. $count; my @b = map log @a; cmpthese( -5, { 1 => sub { my %h; keys %h = @a; $h{ $_ } = log for @a; return \%h }, 2 => sub { my %h; $h{ $_ } = log for @a; return \%h }, 3 => sub { my %h; keys %h = @a; @h{ @a } = @b; return \%h }, 4 => sub { my %h; @h{ @a } = @b; return \%h }, }) } $ perl5240o ~/tmp/x.pl Rate 2 1 4 3 2 14381/s -- -1% -25% -26% 1 14516/s 1% -- -24% -26% 4 19198/s 33% 32% -- -2% 3 19510/s 36% 34% 2% -- Rate 2 1 4 3 2 1427/s -- -4% -25% -29% 1 1480/s 4% -- -22% -26% 4 1895/s 33% 28% -- -5% 3 2004/s 40% 35% 6% -- Rate 2 1 4 3 2 131/s -- -6% -22% -29% 1 140/s 6% -- -17% -25% 4 168/s 28% 20% -- -9% 3 185/s 41% 33% 10% -- Rate 2 1 4 3 2 6.50/s -- -6% -12% -18% 1 6.94/s 7% -- -6% -12% 4 7.39/s 14% 6% -- -7% 3 7.91/s 22% 14% 7% -- $