From: Vincent Pit Date: Fri, 23 Jan 2009 21:15:03 +0000 (+0100) Subject: Make the benchmark a little more fair X-Git-Tag: v0.28~8 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=02e289e2e1b107db4724acff320219f108beb6a5;p=perl%2Fmodules%2FVariable-Magic.git Make the benchmark a little more fair --- diff --git a/samples/vm_vs_tie.pl b/samples/vm_vs_tie.pl index 8de8ea9..c712b71 100755 --- a/samples/vm_vs_tie.pl +++ b/samples/vm_vs_tie.pl @@ -12,20 +12,39 @@ use Benchmark qw/cmpthese/; die 'Your perl does not support the nice uvar magic of 5.10.*' unless VMG_UVAR; -my @a = ('a' .. 'z'); - tie my %t, 'Tie::StdHash'; -$t{$a[$_]} = $_ for 0 .. $#a; +$t{a} = 1; -my $wiz = wizard fetch => sub { 0 }, store => sub { 0 }; +my $wiz = wizard fetch => sub { 0 }, + store => sub { 0 }, + exists => sub { 0 }, + delete => sub { 0 }; my %v; -$v{$a[$_]} = $_ for 0 .. $#a; cast %v, $wiz; - -my $x = 0; +$v{a} = 2; print "Using Variable::Magic ", $Variable::Magic::VERSION, "\n"; -cmpthese -3, { - 'tie' => sub { my ($x, $y) = map @a[$x++ % @a], 1 .. 2; my $a = $t{$x}; $t{$y} = $a }, - 'v::m' => sub { my ($x, $y) = map @a[$x++ % @a], 1 .. 2; my $a = $v{$x}; $v{$y} = $a } + +print "Fetch:\n"; +cmpthese -1, { + 'tie' => sub { $t{a} }, + 'v::m' => sub { $v{a} } +}; + +print "Store:\n"; +cmpthese -1, { + 'tie' => sub { $t{a} = 2 }, + 'v::m' => sub { $v{a} = 2 } +}; + +print "Exists:\n"; +cmpthese -1, { + 'tie' => sub { exists $t{a} }, + 'v::m' => sub { exists $v{a} } +}; + +print "Delete/store:\n"; +cmpthese -1, { + 'tie' => sub { delete $t{a}; $t{a} = 3 }, + 'v::m' => sub { delete $v{a}; $v{a} = 3 } };