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

filter: Statementstmt 98.0% 51 / 52 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 2 totaltotal 92.5% 62 / 67 CC 3 SCAR 4.5
CC
3
Cov
95%
main
3.1
regexes
1.0
BEGIN
1.0
CRAP 1.6
« blib/lib/Benchmark/Perl/Formance/Plugin/RxMicro.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/Incubator.pm »
1 package Benchmark::Perl::Formance::Plugin::Rx;
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.002";
11  
12 #############################################################
13 # #
14 # Benchmark Code ahead - Don't touch without strong reason! #
15 # #
16 #############################################################
17  
18 2 ▶use Benchmark ':hireswallclock';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 2 our $goal;
22 2 our $count;
23 2 our $length;
24  
25 sub regexes
26 1 ▶{
Subroutine regexes: called CC=1 SCAR=0.0
Pod undocumented
27 1 my ($options) = @_;
28  
29 # http://swtch.com/~rsc/regexp/regexp1.html
30  
31 1 my $before;
32 my $after;
33 1 my %results = ();
34  
35 {
36 1 my $subtest = "pathological";
37  
38 1 my $n = $goal;
39 1 my $re = ("a?" x $n) . ("a" x $n);
40 1 my $string = "a" x $n;
41  
42 1 ▶ my $t = timeit $count, sub { $string =~ /$re/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
43 1 $results{$subtest} = {
44 Benchmark => $t,
45 goal => $goal,
46 count => $count,
47 };
48 }
49  
50 # ----------------------------------------------------
51  
52 # { "abcdefg", "abcdefg" },
53 # { "(a|b)*a", "ababababab" },
54 # { "(a|b)*a", "aaaaaaaaba" },
55 # { "(a|b)*a", "aaaaaabac" },
56 # { "a(b|c)*d", "abccbcccd" },
57 # { "a(b|c)*d", "abccbcccde" },
58 # { "a(b|c)*d", "abcccccccc" },
59 # { "a(b|c)*d", "abcd" },
60  
61 # ----------------------------------------------------
62  
63 {
64 1 my $subtest = "fieldsplit1";
65  
66 1 my $re = '(.*) (.*) (.*) (.*) (.*)';
67 1 my $string = (("a" x $length) . " ") x 5;
68 1 chop $string;
69  
70 1 ▶ my $t = timeit $count, sub { $string =~ /$re/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
71 1 $results{$subtest} = {
72 Benchmark => $t,
73 goal => $goal,
74 count => $count,
75 };
76 }
77  
78 # ----------------------------------------------------
79  
80 {
81 1 my $subtest = "fieldsplit2";
82  
83 1 my $re = '([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*)';
84 1 my $string = ( ("a" x $length) . " " ) x 5;
85 1 chop $string;
86  
87 1 ▶ my $t = timeit $count, sub { $string =~ /$re/ };
Subroutine __ANON__: called CC=1 SCAR=0.0
88 1 $results{$subtest} = {
89 Benchmark => $t,
90 goal => $goal,
91 count => $count,
92 };
93 }
94  
95 $results{fieldsplitratio} = sprintf(
96 "%0.4f",
97 1 $results{fieldsplit1}{Benchmark}[1] / $results{fieldsplit2}{Benchmark}[1]
98 );
99  
100 # ----------------------------------------------------
101  
102 0 return \%results;
103 }
104  
105 sub main
106 1 ▶{
Subroutine main: called CC=3 SCAR=11.3
Pod undocumented
107 1 my ($options) = @_;
108  
109 1 ▶ $goal = $options->{fastmode} ? 20 : 29;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 1 0 1
110 1 ▶ $length = $options->{fastmode} ? 1_000_000 : 10_000_000;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 1 0 1
111 1 $count = 5;
112  
113 return {
114 1 regexes => regexes($options),
115 };
116 }
117  
118 2 1;
119  
120 __END__
« blib/lib/Benchmark/Perl/Formance/Plugin/RxMicro.pm ↑ Summary blib/lib/Benchmark/Perl/Formance/Plugin/Incubator.pm »