]> git.vpit.fr Git - perl/modules/autovivification.git/blob - samples/bench.pl
Add a sample benchmark
[perl/modules/autovivification.git] / samples / bench.pl
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Benchmark qw/cmpthese/;
7
8 my $count = -1;
9
10 {
11  my %h = (
12   a => 1,
13  );
14
15  cmpthese $count, {
16   fetch_hash_existing_av   => sub { $h{a} },
17   fetch_hash_existing_noav => sub { no autovivification; $h{a} },
18  };
19 }
20
21 {
22  my %h = ();
23
24  cmpthese $count, {
25   fetch_hash_nonexisting_av   => sub { $h{a} },
26   fetch_hash_nonexisting_noav => sub { no autovivification; $h{a} },
27  };
28 }
29
30 {
31  my $x = {
32   a => 1,
33  };
34
35  cmpthese $count, {
36   fetch_hashref_existing_av   => sub { $x->{a} },
37   fetch_hashref_existing_noav => sub { no autovivification; $x->{a} },
38  };
39 }
40
41 {
42  my $x = { };
43
44  cmpthese $count, {
45   fetch_hashref_nonexisting_av   => sub { $x->{a} },
46   fetch_hashref_nonexisting_noav => sub { no autovivification; $x->{a} },
47  };
48 }