PerlStone2015/dpath.pm

filter: Statementstmt 37.5% 18 / 48 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 2 totaltotal 27.8% 22 / 79 CC 10 SCAR 39.5
CC
10
Cov
27%
run_dpath
90.0
main
6.0
__ANON__
2.0
CRAP 51.8
« PerlStone2015.pm ↑ Summary PerlStone2015/regexdna.pm »
1 package Benchmark::Perl::Formance::Plugin::PerlStone2015::dpath;
2 1 our $AUTHORITY = 'cpan:SCHWIGON';
3 # ABSTRACT: benchmark - stress lookup, traversing, and copying of data structures
4 1 $Benchmark::Perl::Formance::Plugin::PerlStone2015::dpath::VERSION = '0.002';
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #############################################################
9 # #
10 # Benchmark Code ahead - Don't touch without strong reason! #
11 # #
12 #############################################################
13  
14 1 our $goal;
15 1 our $count;
16  
17 1 ▶use Clone 'clone';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Benchmark ':all', ':hireswallclock';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # example use-case is a medium sized TAP-DOM, which we blow up
21 1 my $base_data = {
22 'parse_errors' => [
23 'Bad plan. You planned 6 tests but ran 8.'
24 ],
25 'tests_run' => 8,
26 'version' => 13,
27 'exit' => 0,
28 'start_time' => '1236463400.25151',
29 'skip_all' => undef,
30 'lines' => [
31 {
32 'is_comment' => 0,
33 'has_skip' => 0,
34 'as_string' => 'TAP version 13',
35 'is_test' => 0,
36 'is_yaml' => 0,
37 'is_plan' => 0,
38 'is_actual_ok' => 0,
39 'is_unknown' => 0,
40 'has_todo' => 0,
41 'is_bailout' => 0,
42 'is_pragma' => 0,
43 'is_version' => 1,
44 'raw' => 'TAP version 13'
45 },
46 {
47 'is_comment' => 0,
48 'has_skip' => 0,
49 'as_string' => '1..6',
50 'is_test' => 0,
51 'is_yaml' => 0,
52 'is_plan' => 1,
53 'is_actual_ok' => 0,
54 'is_unknown' => 0,
55 'has_todo' => 0,
56 'is_bailout' => 0,
57 'is_pragma' => 0,
58 'is_version' => 0,
59 'raw' => '1..6'
60 },
61 {
62 'is_comment' => 0,
63 'is_yaml' => 0,
64 'is_plan' => 0,
65 'number' => '1',
66 'is_unknown' => 0,
67 'is_bailout' => 0,
68 'is_pragma' => 0,
69 'is_unplanned' => 0,
70 'as_string' => 'ok 1 - use Data::DPath;',
71 'has_skip' => 0,
72 'is_test' => 1,
73 '_children' => [
74 {
75 'is_comment' => 0,
76 'has_skip' => 0,
77 'as_string' => ' ---
78 - name: \'Hash one\'
79 value: 1
80 - name: \'Hash two\'
81 value: 2
82 ...',
83 'is_test' => 0,
84 'is_yaml' => 1,
85 'is_plan' => 0,
86 'data' => [
87 {
88 'value' => '1',
89 'name' => 'Hash one'
90 },
91 {
92 'value' => '2',
93 'name' => 'Hash two'
94 }
95 ],
96 'is_actual_ok' => 0,
97 'is_unknown' => 0,
98 'has_todo' => 0,
99 'is_bailout' => 0,
100 'is_pragma' => 0,
101 'is_version' => 0,
102 'raw' => ' ---
103 - name: \'Hash one\'
104 value: 1
105 - name: \'Hash two\'
106 value: 2
107 ...'
108 }
109 ],
110 'is_actual_ok' => 0,
111 'description' => '- use Data::DPath;',
112 'is_ok' => 1,
113 'has_todo' => 0,
114 'explanation' => '',
115 'directive' => '',
116 'type' => 'test',
117 'is_version' => 0,
118 'raw' => 'ok 1 - use Data::DPath;'
119 },
120 {
121 'is_comment' => 0,
122 'is_yaml' => 0,
123 'is_plan' => 0,
124 'number' => '2',
125 'is_unknown' => 0,
126 'is_bailout' => 0,
127 'is_pragma' => 0,
128 'is_unplanned' => 0,
129 'as_string' => 'ok 2 - KEYs + PARENT',
130 'has_skip' => 0,
131 'is_test' => 1,
132 'is_actual_ok' => 0,
133 'description' => '- KEYs + PARENT',
134 'is_ok' => 1,
135 'has_todo' => 0,
136 'explanation' => '',
137 'directive' => '',
138 'type' => 'test',
139 'is_version' => 0,
140 'raw' => 'ok 2 - KEYs + PARENT'
141 },
142 {
143 'is_comment' => 0,
144 'is_yaml' => 0,
145 'is_plan' => 0,
146 'number' => '3',
147 'is_unknown' => 0,
148 'is_bailout' => 0,
149 'is_pragma' => 0,
150 'is_unplanned' => 0,
151 'as_string' => 'ok 3 - quoted KEY containg slash',
152 'has_skip' => 0,
153 'is_test' => 1,
154 'is_actual_ok' => 0,
155 'description' => '- quoted KEY containg slash',
156 'is_ok' => 1,
157 'has_todo' => 0,
158 'explanation' => '',
159 'directive' => '',
160 'type' => 'test',
161 'is_version' => 0,
162 'raw' => 'ok 3 - quoted KEY containg slash'
163 },
164 {
165 'is_comment' => 0,
166 'has_skip' => 0,
167 'as_string' => 'pragma +strict',
168 'is_test' => 0,
169 'is_yaml' => 0,
170 'is_plan' => 0,
171 'is_actual_ok' => 0,
172 'is_unknown' => 0,
173 'has_todo' => 0,
174 'is_bailout' => 0,
175 'is_pragma' => 1,
176 'is_version' => 0,
177 'raw' => 'pragma +strict'
178 },
179 {
180 'is_comment' => 0,
181 'is_yaml' => 0,
182 'is_plan' => 0,
183 'number' => '4',
184 'is_unknown' => 0,
185 'is_bailout' => 0,
186 'is_pragma' => 0,
187 'is_unplanned' => 0,
188 'as_string' => 'not ok 4 # TODO spec only',
189 'has_skip' => 0,
190 'is_test' => 1,
191 '_children' => [
192 {
193 'is_comment' => 1,
194 'has_skip' => 0,
195 'as_string' => '# Failed (TODO) test at t/data_dpath.t line 144.',
196 'is_test' => 0,
197 'is_yaml' => 0,
198 'is_plan' => 0,
199 'is_actual_ok' => 0,
200 'is_unknown' => 0,
201 'has_todo' => 0,
202 'is_bailout' => 0,
203 'is_pragma' => 0,
204 'is_version' => 0,
205 'raw' => '# Failed (TODO) test at t/data_dpath.t line 144.'
206 },
207 {
208 'is_comment' => 1,
209 'has_skip' => 0,
210 'as_string' => '# Structures begin differing at:',
211 'is_test' => 0,
212 'is_yaml' => 0,
213 'is_plan' => 0,
214 'is_actual_ok' => 0,
215 'is_unknown' => 0,
216 'has_todo' => 0,
217 'is_bailout' => 0,
218 'is_pragma' => 0,
219 'is_version' => 0,
220 'raw' => '# Structures begin differing at:'
221 },
222 {
223 'is_comment' => 1,
224 'has_skip' => 0,
225 'as_string' => '# $got->[0] = Does not exist',
226 'is_test' => 0,
227 'is_yaml' => 0,
228 'is_plan' => 0,
229 'is_actual_ok' => 0,
230 'is_unknown' => 0,
231 'has_todo' => 0,
232 'is_bailout' => 0,
233 'is_pragma' => 0,
234 'is_version' => 0,
235 'raw' => '# $got->[0] = Does not exist'
236 },
237 {
238 'is_comment' => 1,
239 'has_skip' => 0,
240 'as_string' => '# $expected->[0] = ARRAY(0x8e4c238)',
241 'is_test' => 0,
242 'is_yaml' => 0,
243 'is_plan' => 0,
244 'is_actual_ok' => 0,
245 'is_unknown' => 0,
246 'has_todo' => 0,
247 'is_bailout' => 0,
248 'is_pragma' => 0,
249 'is_version' => 0,
250 'raw' => '# $expected->[0] = ARRAY(0x8e4c238)'
251 }
252 ],
253 'is_actual_ok' => 0,
254 'description' => '',
255 'is_ok' => 1,
256 'has_todo' => 1,
257 'explanation' => 'spec only',
258 'directive' => 'TODO',
259 'type' => 'test',
260 'is_version' => 0,
261 'raw' => 'not ok 4 # TODO spec only'
262 },
263 {
264 'is_comment' => 0,
265 'is_yaml' => 0,
266 'is_plan' => 0,
267 'number' => '5',
268 'is_unknown' => 0,
269 'is_bailout' => 0,
270 'is_pragma' => 0,
271 'is_unplanned' => 0,
272 'as_string' => 'ok 5 - ANYWHERE + KEY + FILTER int # TODO spec only',
273 'has_skip' => 0,
274 'is_test' => 1,
275 'is_actual_ok' => 1,
276 'description' => '- ANYWHERE + KEY + FILTER int',
277 'is_ok' => 1,
278 'has_todo' => 1,
279 'explanation' => 'spec only',
280 'directive' => 'TODO',
281 'type' => 'test',
282 'is_version' => 0,
283 'raw' => 'ok 5 - ANYWHERE + KEY + FILTER int # TODO spec only'
284 },
285 {
286 'is_comment' => 0,
287 'is_yaml' => 0,
288 'is_plan' => 0,
289 'number' => '6',
290 'is_unknown' => 0,
291 'is_bailout' => 0,
292 'is_pragma' => 0,
293 'is_unplanned' => 0,
294 'as_string' => 'ok 6 # SKIP rethink twice',
295 'has_skip' => 1,
296 'is_test' => 1,
297 'is_actual_ok' => 0,
298 'description' => '',
299 'is_ok' => 1,
300 'has_todo' => 0,
301 'explanation' => 'rethink twice',
302 'directive' => 'SKIP',
303 'type' => 'test',
304 'is_version' => 0,
305 'raw' => 'ok 6 # skip rethink twice'
306 },
307 {
308 'is_comment' => 0,
309 'is_yaml' => 0,
310 'is_plan' => 0,
311 'number' => '7',
312 'is_unknown' => 0,
313 'is_bailout' => 0,
314 'is_pragma' => 0,
315 'is_unplanned' => 1,
316 'as_string' => 'not ok 7 # TODO spec only',
317 'has_skip' => 0,
318 'is_test' => 1,
319 '_children' => [
320 {
321 'is_comment' => 1,
322 'has_skip' => 0,
323 'as_string' => '# Failed (TODO) test at t/data_dpath.t line 356.',
324 'is_test' => 0,
325 'is_yaml' => 0,
326 'is_plan' => 0,
327 'is_actual_ok' => 0,
328 'is_unknown' => 0,
329 'has_todo' => 0,
330 'is_bailout' => 0,
331 'is_pragma' => 0,
332 'is_version' => 0,
333 'raw' => '# Failed (TODO) test at t/data_dpath.t line 356.'
334 },
335 {
336 'is_comment' => 1,
337 'has_skip' => 0,
338 'as_string' => '# Structures begin differing at:',
339 'is_test' => 0,
340 'is_yaml' => 0,
341 'is_plan' => 0,
342 'is_actual_ok' => 0,
343 'is_unknown' => 0,
344 'has_todo' => 0,
345 'is_bailout' => 0,
346 'is_pragma' => 0,
347 'is_version' => 0,
348 'raw' => '# Structures begin differing at:'
349 },
350 {
351 'is_comment' => 1,
352 'has_skip' => 0,
353 'as_string' => '# $got->[0] = Does not exist',
354 'is_test' => 0,
355 'is_yaml' => 0,
356 'is_plan' => 0,
357 'is_actual_ok' => 0,
358 'is_unknown' => 0,
359 'has_todo' => 0,
360 'is_bailout' => 0,
361 'is_pragma' => 0,
362 'is_version' => 0,
363 'raw' => '# $got->[0] = Does not exist'
364 },
365 {
366 'is_comment' => 1,
367 'has_skip' => 0,
368 'as_string' => '# $expected->[0] = \'interesting value\'',
369 'is_test' => 0,
370 'is_yaml' => 0,
371 'is_plan' => 0,
372 'is_actual_ok' => 0,
373 'is_unknown' => 0,
374 'has_todo' => 0,
375 'is_bailout' => 0,
376 'is_pragma' => 0,
377 'is_version' => 0,
378 'raw' => '# $expected->[0] = \'interesting value\''
379 }
380 ],
381 'is_actual_ok' => 0,
382 'description' => '',
383 'is_ok' => 0,
384 'has_todo' => 1,
385 'explanation' => 'spec only',
386 'directive' => 'TODO',
387 'type' => 'test',
388 'is_version' => 0,
389 'raw' => 'not ok 7 # TODO spec only'
390 },
391 {
392 'is_comment' => 0,
393 'is_yaml' => 0,
394 'is_plan' => 0,
395 'number' => '8',
396 'is_unknown' => 0,
397 'is_bailout' => 0,
398 'is_pragma' => 0,
399 'is_unplanned' => 1,
400 'as_string' => 'ok 8 - FILTER eval regex # TODO too dirty, first cleanup _filter_eval',
401 'has_skip' => 0,
402 'is_test' => 1,
403 'is_actual_ok' => 1,
404 'description' => '- FILTER eval regex',
405 'is_ok' => 0,
406 'has_todo' => 1,
407 'explanation' => 'too dirty, first cleanup _filter_eval',
408 'directive' => 'TODO',
409 'type' => 'test',
410 'is_version' => 0,
411 'raw' => 'ok 8 - FILTER eval regex # TODO too dirty, first cleanup _filter_eval'
412 },
413 ],
414 'is_good_plan' => 0,
415 'has_problems' => 2,
416 'end_time' => '1236463400.25468',
417 'pragmas' => [
418 'strict'
419 ],
420 'plan' => '1..6',
421 'tests_planned' => 6
422 };
423  
424 sub run_dpath
425 0 ▶{
Subroutine run_dpath: not called CC=9 SCAR=45.0
Pod undocumented
426 0 my ($options) = @_;
427  
428 0 eval "use Data::DPath 'dpath'"; ## no critic
429  
430 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
431 0 ▶ print STDERR "# ".$@ if $options->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} > 2 0 0 0
432 0 return { failed => "use Data::DPath failed" };
433 }
434  
435 0 my $resultlist;
436  
437 # ---------- prepare ----------
438  
439 0 my $path = '//lines//description[ value =~ m(use Data::DPath) ]/../_children//data//name[ value eq "Hash two"]/../value';
440 0 my $expected = "2";
441  
442 0 $resultlist = [ dpath($path)->match($base_data) ];
443 0 ▶ print STDERR "# Prepare big data ..." if $options->{verbose} && $options->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} and $options->{"verbose"} > 2 0 0 0
Condition0%0/3
$options->{"verbose"} and $options->{"verbose"} > 2
!ll&&!rl&&r
000
MC/DC0%0/2
$options->{"verbose"} and $options->{"verbose"} > 2
$options->{"verbose"} $options->{"verbose"} > 2
Truth table0%0/3
A and B
A= $options->{"verbose"}B= $options->{"verbose"} > 2
ABresult
0X0
100
111
444 0 my $huge_data;
445 0 my $multi = $goal;
446  
447 0 my @huge_expected = map { $expected } 1..$multi;
448 0 $huge_data->{$_} = clone ( $base_data ) foreach 1..$multi;
449 0 my $data_size;
450 0 eval qq{use Devel::Size 'total_size'};
451 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
452 0 $data_size = "error-no-Devel-Size-available";
453 } else {
454 0 $data_size = total_size ($huge_data);
455 }
456 0 ▶ print STDERR "# Running benchmark. Can take some time ..." if $options->{verbose} && $options->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} and $options->{"verbose"} > 2 0 0 0
Condition0%0/3
$options->{"verbose"} and $options->{"verbose"} > 2
!ll&&!rl&&r
000
MC/DC0%0/2
$options->{"verbose"} and $options->{"verbose"} > 2
$options->{"verbose"} $options->{"verbose"} > 2
Truth table0%0/3
A and B
A= $options->{"verbose"}B= $options->{"verbose"} > 2
ABresult
0X0
100
111
457  
458 0 my $t;
459 my $result;
460 0 ▶ $t = timeit ($count, sub { $resultlist = [ dpath($path)->match($huge_data) ] });
Subroutine __ANON__: not called CC=1 SCAR=6.9
461 return {
462 0 Benchmark => $t,
463 result => $resultlist->[0],
464 data_size => $data_size,
465 goal => $goal,
466 };
467 }
468  
469  
470 0 ▶sub main {
Subroutine main: not called CC=2 SCAR=17.9
Pod undocumented
471 0 my ($options) = @_;
472  
473 # we are interested in raw Perl speed
474 0 local $Data::DPath::USE_SAFE = 0;
475  
476 0 ▶ $goal = $options->{fastmode} ? 15 : 1000;
Branch: 1 branch
BranchTrueFalseTotal
$options->{'fastmode'} ? : 0 0 0
477 0 $count = 5;
478  
479 0 return run_dpath();
480 }
481  
482 1 1;
483  
484 __END__
« PerlStone2015.pm ↑ Summary PerlStone2015/regexdna.pm »