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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/usr/bin/env perl
use warnings; use strict;
use Benchmark qw(:all);
use Data::Dumper;
use IPC::Shareable;
if (@ARGV < 1){
print "\n Need test count argument...\n\n";
exit;
}
my $timethis = 1;
my $timethese = 0;
my $cmpthese = 0;
if ($timethis) {
timethis($ARGV[0], \&shareable);
#timethis($ARGV[0], \&sharedhash);
}
if ($timethese) {
timethese($ARGV[0],
{
'shareable' => \&shareable,
# 'shared_hash' => \&sharedhash,
},
);
}
if ($cmpthese) {
cmpthese($ARGV[0],
{
'shareable' => \&shareable,
# 'sharedhash ' => \&sharedhash,
},
);
}
sub default {
return {
a => 1,
b => 2,
c => [qw(1 2 3)],
d => {z => 26, y => 25},
};
}
sub shareable {
work('IPC::Shareable');
}
sub sharedhash {
# work('IPC::SharedHash');
}
sub work {
my ($pkg) = @_;
my $base_data = default();
tie my %hash, $pkg, {
key => 'hash',
create => 1,
destroy => 1,
};
%hash = %$base_data;
for (1..100) {
$hash{struct} = { a => [ qw(b c d) ] };
$hash{array} = [ qw(1 2 3) ];
$hash{b} = 3;
delete $hash{b};
$hash{b} = 4;
}
tied(%hash)->clean_up_all;
}
__END__
Rate shareable sharedhash
shareable 223/s -- -95%
sharedhash 4808/s 2058% --
|