makebench.PL

filter: Statementstmt 92.3% 96 / 104 Branchbran 75.0% 30 / 40 Conditioncond 8.3% 1 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 66.6% 2 / 3 Podpod n/a totaltotal 78.1% 129 / 165 CC 25 SCAR 33.9
CC
25
Cov
81%
has_cc
56.0
tmplfile
21.6
BEGIN
1.0
CRAP 29.8
« blib/lib/XML/Bare.pm ↑ Summary parser.c »
1 #!/usr/bin/perl -w
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶if( !eval( "require Time::HiRes;" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval "require Time::HiRes;") 0 1 1
6 0 print "Time::HiRes not installed; benchmarks cannot be done\n";
7 }
8  
9 1 opendir( DIR, "./bench" );
10 1 my @files = readdir(DIR);
11 1 closedir( DIR );
12 1 foreach my $file ( @files ) {
13 16 ▶ if( $file =~ m/(.+)\.tmpl/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /(.+)\.tmpl/) 3 13 16
14 3 print "Processing $file\n";
15 3 tmplfile( './bench/'.$file, $1 );
16 3 print "\n";
17 }
18 }
19  
20 3 ▶sub tmplfile {
Subroutine tmplfile: called CC=19 SCAR=30.7
21 3 my $file = shift;
22 3 my $name = shift;
23 3 open(TMPL,"$file");
24 3 $/ = undef;
25 3 my $tmpl = <TMPL>;
26 3 close(TMPL);
27  
28 3 $tmpl =~ s/#([c+0-])/#-$1/g;
29  
30 #print $tmpl;
31 3 my @parts = split('#-',$tmpl);
32  
33 3 open(OUT,">./bench/one$name.pl");
34  
35 3 my $div;
36 0 ▶sub has_cc {
Subroutine has_cc: not called CC=7 SCAR=40.3
37 0 ▶ my $div = (substr($ENV{'PATH'},0,1) eq '/') ? ':' : ';';
Branch: 1 branch
BranchTrueFalseTotal
substr($ENV{'PATH'}, 0, 1) eq '/' ? : 0 0 0
38 0 my @path = split($div,$ENV{'PATH'});
39 0 foreach my $dir ( @path ) {
40 0 ▶ return 1 if( -e "$dir/cc" ||
Branch: 1 branch
BranchTrueFalseTotal
if -e "$dir/cc" or -e "$dir/gcc" or -e "$dir/cc.exe" or -e "$dir/gcc.exe" 0 0 0
Condition0%0/9
-e "$dir/cc" or -e "$dir/gcc" or -e "$dir/cc.exe" or -e "$dir/gcc.exe"
l!l&&r!l&&!r
000
-e "$dir/cc" or -e "$dir/gcc" or -e "$dir/cc.exe"
l!l&&r!l&&!r
000
-e "$dir/cc" or -e "$dir/gcc"
l!l&&r!l&&!r
000
MC/DC0%0/4
-e "$dir/cc" or -e "$dir/gcc" or -e "$dir/cc.exe" or -e "$dir/gcc.exe"
-e "$dir/cc" -e "$dir/gcc" -e "$dir/cc.exe" -e "$dir/gcc.exe"
Truth table0%0/5
A or B or C or D
A= -e "$dir/cc"B= -e "$dir/gcc"C= -e "$dir/cc.exe"D= -e "$dir/gcc.exe"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
41 -e "$dir/gcc" ||
42 -e "$dir/cc.exe" ||
43 -e "$dir/gcc.exe" ); }
44 0 return 0;
45 }
46 0 ▶if( $^O eq 'MSWin32' && !has_cc() ) { $div = '\\'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32' and not has_cc()) { } 0 3 3
Condition33%1/3
$^O eq "MSWin32" and not has_cc()
!ll&&!rl&&r
300
MC/DC0%0/2
$^O eq "MSWin32" and not has_cc()
$^O eq "MSWin32" not has_cc()
Truth table33%1/3
A and not(B)
A= $^O eq "MSWin32"B= not has_cc()
ABresult
0X0
100
111
47 3 else { $div = '/'; }
48  
49 3 print OUT <<START;
50 #!/usr/bin/perl
51 use strict;
52  
53 my \$div = "\\$div";
54 my \$maxlen = 26;
55 my \$file = \$ARGV[1] || 'test.xml';
56 my ( \$root, \$s, \$s2, \$s3, \$usec, \$usec2, \$usec3, \$sa, \$sb, \$sc, \$base1, \$base2, \$base3 );
57  
58 my \$onlyone = \$ARGV[2] ? 1 : 0;
59  
60 tabit("-Module-",'load ','parse ','total') if( !\$onlyone );
61  
62 exit if( !\$ARGV[0] );
63  
64 use Time::HiRes qw(gettimeofday);
65  
66 # For fairness; try to get the file to be read into memory cache
67 {
68 open(FILE,'<', \$file) or die "Couldn't open \$!";
69 local \$/ = undef; my \$cache = <FILE>;
70 close(FILE);
71 }
72 START
73  
74 #{
75 # (\$s, \$usec) = gettimeofday();
76 # if( eval( "require XML::Bare;" ) ) {
77 # (\$s2, \$usec2) = gettimeofday();
78 # my \$ob = new XML::Bare( file => \$file );
79 # \$root = \$ob->parse();
80 # (\$s3, \$usec3) = gettimeofday();
81 # timeit('XML::Bare',1);
82 # }
83 #}
84 #START
85 3 my $comment = '';
86 3 my $i = -1;
87 3 foreach my $part ( @parts ) {
88 38 my @requires;
89 38 $part = '#'.$part;
90 38 my $type = '';
91 38 my $module = '';
92 38 ▶ if( $part =~ m/#([c\-0\+]) (.+)\n/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /#([c\-0\+]) (.+)\n/) 8 30 38
93 8 $type = $1;
94 8 my $name = $2;
95 8 ▶ $module = $name if( $name =~ m/\w/ );
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /\w/ 8 0 8
96 }
97 38 ▶ if( $part =~ m/#([c\-0\+]\+?)\n/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /#([c\-0\+]\+?)\n/) 27 11 38
98 27 $type = $1;
99 }
100 #print "[$type $module]\n";
101
102 38 ▶ if( $type eq 'c' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "c") 3 35 38
103 3 $part =~ s/c\n//g;
104 3 $part = "##".$part."##";
105 3 $part =~ s/^##[#c \n]+//;
106 3 $part =~ s/[ \n]+##$//;
107 3 $comment = $part;
108 3 next;
109 }
110 35 ▶ if( $type eq '0' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 0) 2 33 35
111
112 2 ▶ if( $module ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module) 0 2 2
113 0 $part =~ s/(#0)\W*.*/$1/;
114 }
115
116 2 ▶ while( $part =~ m/(require [A-Za-z\:]+;)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /(require [A-Za-z\:]+;)/g) 2 2 4
117 2 my $req = $1;
118 2 ▶ if( !$module ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module) 2 0 2
119 2 my $fmod = $req;
120 2 $fmod =~ s/require //; $fmod =~ s/;//;
121 2 $module = $fmod;
122 }
123 2 push( @requires, $req );
124 }
125 2 $part =~ s/require [A-Za-z\:]+;\n//g;
126
127 2 $part = "##".$part."##";
128 2 $part =~ s/^##[#0 \n]+//;
129 2 $part =~ s/[ \n]+##$//;
130
131 2 print OUT "
132 if( \$ARGV[0]*1 >= $i ) {
133 (\$s, \$usec) = gettimeofday();
134 if( eval( '@requires' ) ) {
135 (\$s2, \$usec2) = gettimeofday();
136
137 $part
138  
139 (\$s3, \$usec3) = gettimeofday();
140 unload('$module');
141 timeit('$module',1);
142 }
143 }
144 ";
145 }
146 35 ▶ if( $type eq '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "-") 26 9 35
147
148 26 ▶ if( $module ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module) 8 18 26
149 8 $part =~ s/(#[\-\0\+])\W*.*/$1/;
150 }
151
152 26 ▶ while( $part =~ m/(require [A-Za-z\:]+;)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part =~ /(require [A-Za-z\:]+;)/g) 29 26 55
153 29 my $req = $1;
154 29 ▶ if( !$module ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module) 18 11 29
155 18 my $fmod = $req;
156 18 $fmod =~ s/require //; $fmod =~ s/;//;
157 18 $module = $fmod;
158 }
159 29 push( @requires, $req );
160 }
161 26 $part =~ s/require [A-Za-z\:]+;\n//g;
162
163 26 $part = "##".$part."##";
164 26 $part =~ s/^##[#\- \n]+//;
165 26 $part =~ s/[ \n]+##$//;
166
167 26 print OUT "
168 if( \$ARGV[0] eq '$i' ) {
169 (\$s, \$usec) = gettimeofday();
170 if( eval( '@requires' ) ) {
171 (\$s2, \$usec2) = gettimeofday();
172
173 $part
174  
175 (\$s3, \$usec3) = gettimeofday();
176 unload('$module');
177 timeit('$module');
178 }
179 }
180 ";
181 }
182 35 ▶ if( $type eq '+' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "+") 3 32 35
183 3 $part = "##".$part."##";
184 3 $part =~ s/^##[#\+ \n]+//;
185 3 $part =~ s/[ \n]+##$//;
186 3 print OUT "
187 if( \$ARGV[0] eq '$i' ) {
188
189 $part
190
191 }
192 ";
193 }
194 35 ▶ if( $type eq '0+' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "0+") 1 34 35
195 1 $part = "##".$part."##";
196 1 $part =~ s/^##[0#\+ \n]+//;
197 1 $part =~ s/[ \n]+##$//;
198 1 print OUT "
199 #if( \$ARGV[0] eq '$i' ) {
200
201 $part
202
203 #}
204 ";
205 }
206 35 $i++;
207 }
208  
209 3 print OUT <<END;
210  
211 sub unload {
212 my \$module = shift;
213 my \@parts = split(' ',\$module);
214 \$module = \$parts[0];
215 \$module =~ s/::/\\//g;
216 \$module.='.pm';
217 delete \$INC{\$module};
218 }
219  
220 sub timeit {
221 my \$name = shift;
222 my \$base = shift;
223 \$sa = \$s2-\$s + ((\$usec2-\$usec)/1000000);
224 \$sb = \$s3-\$s2 + ((\$usec3-\$usec2)/1000000);
225 \$sc = \$s3-\$s + ((\$usec3-\$usec)/1000000);
226 if( \$base ) {
227 \$base1 = \$sa;
228 \$base2 = \$sb;
229 \$base3 = \$sc;
230 }
231 \$sa /= \$base1; \$sb /= \$base2; \$sc /= \$base3;
232 \$sa = fixed( \$sa ); \$sb = fixed( \$sb ); \$sc = fixed( \$sc );
233 if( !\$base || !\$onlyone ) {
234 tabit( \$name,\$sa,\$sb,\$sc);
235 }
236 }
237  
238 sub tabit {
239 my ( \$a, \$b, \$c, \$d ) = \@_;
240 my \$len = length( \$a );
241 print \$a;
242 for( 0..(\$maxlen-\$len) ) { print ' '; }
243 print "\$b \$c \$d\n";
244 }
245  
246 sub fixed {
247 my \$in = shift;
248 \$in *= 10000;
249 \$in = int( \$in );
250 \$in /= 10000;
251 my \$a = "\$in";
252 my \$len = length( \$a );
253 if( \$len > 8 ) { \$a = substr( \$a, 8 ); }
254 if( \$len < 8 ) {
255 while( \$len < 8 ) {
256 \$a = "\${a} ";
257 \$len = length( \$a );
258 }
259 }
260 return \$a;
261 }
262 END
263  
264 3 close(OUT);
265  
266 3 open( SH, ">./bench/$name.pl" );
267  
268 3 my $end = $i+1;
269 3 print SH "#!/usr/bin/perl
270 ";
271 3 ▶if( $comment ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comment) 3 0 3
272 3 print SH "
273 print <<END;
274 $comment
275  
276 END
277 ";
278 }
279 3 print SH
280 "print `perl one$name.pl $end`;
281 my \$file = \$ARGV[0] || 'test.xml';
282 for my \$i ( 0..$i ) {
283 print `perl one$name.pl \$i \$file 1`
284 }
285 ";
286  
287 #print SH "#!/bin/bash
288 #perl bench.pl $end
289 #for (( i=1;i<=$i;i++ )); do
290 #perl bench.pl \$i \$1 1
291 #done
292 #";
293  
294 3 close( SH );
295 }
« blib/lib/XML/Bare.pm ↑ Summary parser.c »