X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=samples%2Fvm_vs_tie.pl;fp=samples%2Fvm_vs_tie.pl;h=9c8cae42e241b71b232f9617ba50c318caf34903;hb=fee1a480bc5d827590dc7394e0a77741bad86dc3;hp=0000000000000000000000000000000000000000;hpb=751094f5d7b43171afc7104e957ca7fe2d21eb34;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/samples/vm_vs_tie.pl b/samples/vm_vs_tie.pl new file mode 100755 index 0000000..9c8cae4 --- /dev/null +++ b/samples/vm_vs_tie.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Tie::Hash; + +use lib qw{blib/arch blib/lib}; +use Variable::Magic qw/wizard cast VMG_UVAR/; + +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; + +my $wiz = wizard fetch => sub { 0 }, store => sub { 0 }; +my %v; +$v{$a[$_]} = $_ for 0 .. $#a; +cast %v, $wiz; + +cmpthese -3, { + 'tie' => sub { my ($x, $y) = map @a[rand @a], 1 .. 2; my $a = $t{$x}; $t{$y} = $a }, + 'v::m' => sub { my ($x, $y) = map @a[rand @a], 1 .. 2; my $a = $v{$x}; $v{$y} = $a } +};