X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=samples%2Fbench.pl;fp=samples%2Fbench.pl;h=bb55856e5ca1b898e7ef351de1a07cdd2ec0294b;hb=163db83e6bed822438bd543d29a1a2b18d0062ba;hp=0000000000000000000000000000000000000000;hpb=daea523653756bb45d89c7b17bbc6ac70f37019d;p=perl%2Fmodules%2Fautovivification.git diff --git a/samples/bench.pl b/samples/bench.pl new file mode 100644 index 0000000..bb55856 --- /dev/null +++ b/samples/bench.pl @@ -0,0 +1,48 @@ +#!perl + +use strict; +use warnings; + +use Benchmark qw/cmpthese/; + +my $count = -1; + +{ + my %h = ( + a => 1, + ); + + cmpthese $count, { + fetch_hash_existing_av => sub { $h{a} }, + fetch_hash_existing_noav => sub { no autovivification; $h{a} }, + }; +} + +{ + my %h = (); + + cmpthese $count, { + fetch_hash_nonexisting_av => sub { $h{a} }, + fetch_hash_nonexisting_noav => sub { no autovivification; $h{a} }, + }; +} + +{ + my $x = { + a => 1, + }; + + cmpthese $count, { + fetch_hashref_existing_av => sub { $x->{a} }, + fetch_hashref_existing_noav => sub { no autovivification; $x->{a} }, + }; +} + +{ + my $x = { }; + + cmpthese $count, { + fetch_hashref_nonexisting_av => sub { $x->{a} }, + fetch_hashref_nonexisting_noav => sub { no autovivification; $x->{a} }, + }; +}