keys my %cache = @in;
$cache{$_} = KEY($_) for @in;
####
keys my %cache = @in;
@cache{@in} = map KEY($_) => @in;
##
##
keys %h = @a;
@h{ @a } = ... ; # do something useful
##
##
use strict;
use warnings;
use Benchmark qw/ cmpthese /;;
for my $count ( 100, 1_000, 10_000, 100_000 ) {
cmpthese( -5, {
1 => sub {
my @a = map { log } 2 .. $count;
my %h;
keys %h = @a;
$h{ $_ } = log for @a;
return \%h
},
2 => sub {
my @a = map { log } 2 .. $count;
my %h;
$h{ $_ } = log for @a;
return \%h
},
3 => sub {
my @a = map { log } 2 .. $count;
my %h;
keys %h = @a;
@h{ @a } = map { log } @a;
return \%h
},
4 => sub {
my @a = map { log } 2 .. $count;
my %h;
@h{ @a } = map { log } @a;
return \%h
},
})
}
##
##
Rate 4 3 2 1
4 1507/s -- -3% -4% -5%
3 1549/s 3% -- -2% -3%
2 1576/s 5% 2% -- -1%
1 1593/s 6% 3% 1% --
Rate 1 2 4 3
1 140/s -- -3% -4% -4%
2 145/s 3% -- -0% -1%
4 145/s 4% 0% -- -0%
3 146/s 4% 1% 0% --
Rate 4 2 3 1
4 12.1/s -- -7% -8% -9%
2 12.9/s 7% -- -2% -3%
3 13.1/s 9% 2% -- -1%
1 13.3/s 10% 3% 1% --
s/iter 4 1 2 3
4 1.39 -- -3% -3% -3%
1 1.35 3% -- -0% -0%
2 1.35 3% 0% -- -0%
3 1.35 3% 0% 0% --