]> git.vpit.fr Git - perl/modules/autovivification.git/commitdiff
Add a sample benchmark
authorVincent Pit <vince@profvince.com>
Sat, 19 Jun 2010 13:14:56 +0000 (15:14 +0200)
committerVincent Pit <vince@profvince.com>
Sat, 19 Jun 2010 13:14:56 +0000 (15:14 +0200)
MANIFEST
samples/bench.pl [new file with mode: 0644]

index 639db05f068e43b0e1a2b5741b014b48e46d5cdb..064ed3e2e882ebad646bc38a330d55cba39aa666 100644 (file)
--- 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 (file)
index 0000000..bb55856
--- /dev/null
@@ -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} },
+ };
+}