]>
Dogcows Code - chaz/p5-CGI-Ex/blob - samples/benchmark/bench_operator_storage.pl
5 bench_operator_storage.pl - Look at different ways of storing operators and how to call them
10 use Benchmark
qw(cmpthese timethese);
11 use CGI
::Ex
::Dump
qw(debug);
12 use constant skip_execute
=> 1;
14 my $total_size = eval { require Devel
::Size
} ? sub { Devel
::Size
::total_size
($_[0]) } : sub { "Skip Devel::Size check" };
16 ###----------------------------------------------------------------###
17 ### check basic setting speed - almost irrelvant as we are in the 300_000's
19 my $set_w_ref = sub { my $s = [ \
[ '+', 4, 5], 0] };
20 my $set_undef = sub { my $s = [ [undef, '+', 4, 5], 0] };
21 my $set_array = sub { my $s = [ [[ '+', 4, 5]], 0] };
22 my $set_arra2 = sub { my $s = [ [[], '+', 4, 5], 0] };
23 my $set_bless = sub { my $s = [ bless([ '+', 4, 5],'CGI::Ex::Template::Op::foo'), 0] };
25 print "Set_w_ref size: ". $total_size->($set_w_ref->()) ."\n";
26 print "Set_undef size: ". $total_size->($set_undef->()) ."\n";
27 print "Set_array size: ". $total_size->($set_array->()) ."\n";
28 print "Set_arra2 size: ". $total_size->($set_arra2->()) ."\n";
29 print "Set_bless size: ". $total_size->($set_bless->()) ."\n";
31 cmpthese timethese
-1, {
32 set_w_ref
=> $set_w_ref,
33 set_undef
=> $set_undef,
34 set_array
=> $set_array,
35 set_arra2
=> $set_arra2,
36 set_bless
=> $set_bless,
39 ###----------------------------------------------------------------###
40 ### time basic variable checking
42 my $check_w_ref = sub {
44 if (ref $s eq 'REF') {
45 $s = $$s->[0] eq '..' ? 1 : 2;
51 my $check_undef = sub {
53 if (! defined $s->[0]) {
54 $s = $s->[1] eq '..' ? 1 : 2;
60 cmpthese timethese
-1, {
61 w_ref_pos
=> sub { $check_w_ref->(\
['+', 4, 5]) },
62 w_ref_dots
=> sub { $check_w_ref->(\
['..', 4, 5]) },
63 w_ref_neg
=> sub { $check_w_ref->(['a', 0]) },
64 undef_pos
=> sub { $check_undef->([undef, '+', 4, 5]) },
65 undef_dots
=> sub { $check_undef->([undef, '..', 4, 5]) },
66 undef_neg
=> sub { $check_undef->(['a', 0]) },
69 ###----------------------------------------------------------------###
70 ### check for calling speed
72 my $play_w_ref = sub {
75 my @args = ($tree->[1], $tree->[2]);
78 my $play_undef = sub {
81 my @args = ($tree->[2], $tree->[3]);
84 my $play_undef2 = sub {
89 my $call_w_ref = sub {
91 return $play_w_ref->($$s);
94 my $call_undef = sub {
96 return $play_undef->($s);
99 my $call_undef2 = sub {
101 return $play_undef2->(@$s[1..$#$s]);
105 cmpthese timethese
-1, {
106 small_w_ref
=> sub { $call_w_ref->(\
['~', 1 .. 2]) },
107 med___w_ref
=> sub { $call_w_ref->(\
['~', 1 .. 200]) },
108 large_w_ref
=> sub { $call_w_ref->(\
['~', 1 .. 2000]) },
109 small_undef
=> sub { $call_undef->([undef, '~', 1 .. 2]) },
110 med___undef
=> sub { $call_undef->([undef, '~', 1 .. 200]) },
111 large_undef
=> sub { $call_undef->([undef, '~', 1 .. 2000]) },
112 small_undef2
=> sub { $call_undef2->([undef, '~', 1 .. 2]) },
113 med___undef2
=> sub { $call_undef2->([undef, '~', 1 .. 200]) },
114 large_undef2
=> sub { $call_undef2->([undef, '~', 1 .. 2000]) },
This page took 0.044907 seconds and 4 git commands to generate.