blib/lib/Benchmark/Perl/Formance/Plugin/RxMicro.pm

filter: Statementstmt 100% 60 / 60 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 2 totaltotal 93.7% 75 / 80 CC 9 SCAR 6.5
CC
9
Cov
95%
main
3.1
rxmicro
2.0
__ANON__
2.0
CRAP 1.9
« blib/lib/Benchmark/Perl/Formance/Plugin/Shootout/nbody.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/Rx.pm »
1 package Benchmark::Perl::Formance::Plugin::RxMicro;
2 2 our $AUTHORITY = 'cpan:SCHWIGON';
3 # ABSTRACT: benchmark plugin - Rx - Stress regular expressions
4  
5 # Regexes
6  
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = "0.003";
11  
12 #############################################################
13 # #
14 # Benchmark Code ahead - Don't touch without strong reason! #
15 # #
16 # The code in here has compile-time and run-time effects! #
17 # #
18 #############################################################
19  
20 2 ▶use Benchmark ':hireswallclock';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 our $goal;
24 2 our $count;
25  
26 sub rxmicro
27 1 ▶{
Subroutine rxmicro: called CC=2 SCAR=6.9
Pod undocumented
28 1 my ($options) = @_;
29  
30 1 my %results = ();
31  
32 # ----------------------------------------------------
33  
34 {
35 # how quickly a pre-compiled regex is accessed:
36  
37 1 my $subtest = "precompile-access";
38 1 my $r = qr/\d+/;
39 1 ▶ my $t = timeit $count, sub { "1234" =~ $r for 1..50000*$goal };
Subroutine __ANON__: called CC=2 SCAR=6.9
40 1 $results{$subtest} = {
41 Benchmark => $t,
42 goal => $goal,
43 count => $count,
44 };
45 }
46  
47 # ----------------------------------------------------
48  
49 {
50 # how quickly run-time regexes are compiled
51  
52 1 my $subtest = "runtime-compile";
53 1 my $r ='\d+';
54 1 ▶ my $t = timeit $count, sub { "1234" =~ $r for 1..100000*$goal };
Subroutine __ANON__: called CC=2 SCAR=6.9
55 1 $results{$subtest} = {
56 Benchmark => $t,
57 goal => $goal,
58 count => $count,
59 };
60 }
61  
62 # ----------------------------------------------------
63  
64 {
65 # run-time regexes are compiled but defeating the caching
66  
67 1 my $subtest = "runtime-compile-nocache";
68 1 my $r ='\d+';
69 1 ▶ my $t = timeit $count, sub { "1234" =~ /$r$_/ for 1..10000*$goal };
Subroutine __ANON__: called CC=2 SCAR=6.9
70 1 $results{$subtest} = {
71 Benchmark => $t,
72 goal => $goal,
73 count => $count,
74 };
75 }
76  
77 # ----------------------------------------------------
78  
79 {
80 # run-time code-blocks
81  
82 1 my $subtest = "code-runtime";
83 1 my $counter;
84 1 my $code = '(?{$counter++})';
85 2 ▶ use re 'eval';
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 1 ▶ my $mygoal = $options->{fastmode} ? 10_000 : 20_000*$goal;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 1 0 1
88  
89 1 ▶ my $t = timeit $count, sub { $counter = 0; "1234" =~ /\d+$code/ for 1..$mygoal };
Subroutine __ANON__: called CC=2 SCAR=6.9
90 1 $results{$subtest} = {
91 Benchmark => $t,
92 goal => $goal,
93 count => $count,
94 counter => $counter,
95 };
96 }
97  
98 # ----------------------------------------------------
99  
100 {
101 # literal code-blocks
102  
103 1 my $cnt;
104 1 my $subtest = "code-literal";
105 1 ▶ my $t = timeit $count, sub { "1234" =~ /\d+(?{$cnt++})/ for 1..40000*$goal };
Subroutine __ANON__: called CC=2 SCAR=6.9
106 1 $results{$subtest} = {
107 Benchmark => $t,
108 goal => $goal,
109 count => $count,
110 };
111 }
112  
113 # ----------------------------------------------------
114  
115 1 return \%results;
116 }
117  
118 sub main
119 1 ▶{
Subroutine main: called CC=3 SCAR=11.4
Pod undocumented
120 1 my ($options) = @_;
121  
122 1 ▶ $goal = $options->{fastmode} ? 20 : 29;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 1 0 1
123 1 ▶ $count = $options->{fastmode} ? 1 : 5;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 1 0 1
124  
125 1 return rxmicro($options);
126 }
127  
128 2 1;
129  
130 __END__
« blib/lib/Benchmark/Perl/Formance/Plugin/Shootout/nbody.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/Rx.pm »