From: Vincent Pit Date: Sat, 19 Jun 2010 13:14:56 +0000 (+0200) Subject: Add a sample benchmark X-Git-Tag: rt62800~14 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=163db83e6bed822438bd543d29a1a2b18d0062ba;p=perl%2Fmodules%2Fautovivification.git Add a sample benchmark --- diff --git a/MANIFEST b/MANIFEST index 639db05..064ed3e 100644 --- a/MANIFEST +++ b/MANIFEST @@ -7,6 +7,7 @@ autovivification.xs lib/autovivification.pm ptable.h reap.h +samples/bench.pl samples/hash2array.pl t/00-load.t t/20-hash.t 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} }, + }; +}