1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
use strict;
use warnings;
use Benchmark qw(:all);
our @la = (1 .. 5);
our @lb = ('one', 'two', 'three', 'four', 'five');
cmpthese(
timethese(
0, # 0 is auto
{
direct => sub {
my %hash = (
1 => 'one',
2 => 'two',
3 => 'three',
4 => 'four',
5 => 'five',
);
},
for => sub {
my %hash;
for my $i (0 .. 4) {
$hash{$la[$i]} = $lb[$i];
}
},
Unroll => sub {
my %hash;
$hash{$la[0]} = $lb[0];
$hash{$la[1]} = $lb[1];
$hash{$la[2]} = $lb[2];
$hash{$la[3]} = $lb[3];
$hash{$la[4]} = $lb[4];
},
slice => sub {
my %hash;
@hash{@la} = @lb;
},
}
)
);
|