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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#!perl -w
use strict;
use Benchmark qw(:all);
use threads ();
use Hash::FieldHash ();
my $HUF;
BEGIN{
if( eval{ require Hash::Util::FieldHash } ){
$HUF = 'Hash::Util::FieldHash';
}
else{
require Hash::Util::FieldHash::Compat;
$HUF = 'Hash::Util::FieldHash::Compat';
}
$HUF->import(qw(fieldhash fieldhashes id));
}
printf "Perl %vd on $^O\n", $^V;
print "$HUF ", $HUF->VERSION, "\n";
print "Hash::FieldHash ", Hash::FieldHash->VERSION, "\n";
cmpthese timethese -2 => {
'H::U::F' => sub{
fieldhashes \my(%huf1, %huf2, %huf3);
my @objects;
for(1 .. 100){
my $o = bless {};
$huf1{$o} = 1;
$huf2{$o} = 2;
$huf3{$o} = 3;
push @objects, $o;
}
for(1 .. 3){
threads->new(sub{ my @a = @objects })->join();
}
},
'H::F' => sub{
Hash::FieldHash::fieldhashes \my(%hf1, %hf2, %hf3);
my @objects;
for(1 .. 100){
my $o = bless {};
$hf1{$o} = 1;
$hf2{$o} = 2;
$hf3{$o} = 3;
push @objects, $o;
}
for(1 .. 3){
threads->new(sub{ my @a = @objects })->join();
}
},
};
|