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

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