This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/perf/benchmarks: tweak cachegrind explanation
[perl5.git] / t / perf / benchmarks
CommitLineData
24fb648d
DM
1#!perl
2
9e7973fa 3# This file specifies an array-of-hashes that define snippets of code that
24fb648d
DM
4# can be run by various measurement and profiling tools.
5#
6# The basic idea is that any time you add an optimisation that is intended
7# to make a particular construct faster, then you should add that construct
8# to this file.
9#
10# Under the normal test suite, the test file benchmarks.t does a basic
11# compile and run of each of these snippets; not to test performance,
12# but just to ensure that the code doesn't have errors.
13#
14# Over time, it is intended that various measurement and profiling tools
15# will be written that can run selected (or all) snippets in various
16# environments. These will not be run as part of a normal test suite run.
17#
9e7973fa
DM
18# It is intended that the tests in this file will be lightweight; e.g.
19# a hash access, an empty function call, or a single regex match etc.
20#
24fb648d
DM
21# This file is designed to be read in by 'do' (and in such a way that
22# multiple versions of this file from different releases can be read in
23# by a single process).
24#
9e7973fa
DM
25# The top-level array has name/hash pairs (we use an array rather than a
26# hash so that duplicate keys can be spotted) Each name is a token that
27# describes a particular test. Code will be compiled in the package named
28# after the token, so it should match /^(\w|::)+$/a. It is intended that
29# this can be used on the command line of tools to select particular
30# tests.
31# In addition, the package names are arranged into an informal hierarchy
32# whose top members are (this is subject to change):
33#
34# call:: subroutine and method handling
35# expr:: expressions: e.g. $x=1, $foo{bar}[0]
84721d61 36# func:: perl functions, e.g. func::sort::...
9e7973fa
DM
37# loop:: structural code like for, while(), etc
38# regex:: regular expressions
39# string:: string handling
24fb648d 40#
9e7973fa
DM
41#
42# Each hash has three fields:
24fb648d
DM
43#
44# desc is a description of the test
45# setup is a string containing setup code
46# code is a string containing the code to run in a loop
47#
48# So typically a benchmark tool might do something like
49#
50# eval "package $token; $setup; for (1..1000000) { $code }"
9e7973fa
DM
51#
52# Currently the only tool that uses this file is Porting/bench.pl;
53# try C<perl Porting/bench.pl --help> for more info
15a75fdb
DM
54#
55# ------
56#
57# Note: for the cachegrind variant, an entry like
58# 'foo::bar' => {
59# setup => 'SETUP',
60# code => 'CODE',
61# }
62# creates two temporary perl sources looking like:
63#
64# package foo::bar;
65# BEGIN { srand(0) }
66# SETUP;
67# for my $__loop__ (1..$ARGV[0]) {
68# 1;
69# }
5247d03d 70#
15a75fdb 71# and as above, but with the '1;' in the loop body replaced with:
5247d03d 72#
15a75fdb
DM
73# CODE;
74#
75# It then pipes each of the two sources into
5247d03d 76#
15a75fdb 77# PERL_HASH_SEED=0 valgrind [options] someperl [options] - N
5247d03d
DM
78#
79# where N is set to 10 and then 20.
80#
81# It then uses the result of those four cachegrind runs to subtract out
82# the perl startup and loop overheads. So only what's in SETUP and CODE
83# can affect the benchmark, and if the loop happens to leave some state
84# changed (such as storing a value in a hash), then the final benchmark
85# timing is the result of running CODE with the hash entry populated
86# rather than empty.
24fb648d
DM
87
88
9e7973fa 89[
e800e134
DM
90 'call::sub::empty' => {
91 desc => 'function call with no args or body',
92 setup => 'sub f { }',
93 code => 'f()',
94 },
f7a874b8
DM
95 'call::sub::amp_empty' => {
96 desc => '&foo function call with no args or body',
97 setup => 'sub f { }; @_ = ();',
98 code => '&f',
99 },
e800e134 100 'call::sub::args3' => {
9e7973fa 101 desc => 'function call with 3 local lexical vars',
e800e134
DM
102 setup => 'sub f { my ($a, $b, $c) = @_; 1 }',
103 code => 'f(1,2,3)',
104 },
f7a874b8
DM
105 'call::sub::args2_ret1' => {
106 desc => 'function call with 2 local lex vars and 1 return value',
107 setup => 'my $x; sub f { my ($a, $b) = @_; $a+$b }',
108 code => '$x = f(1,2)',
109 },
110 'call::sub::args2_ret1temp' => {
111 desc => 'function call with 2 local lex vars and 1 return TEMP value',
112 setup => 'my $x; sub f { my ($a, $b) = @_; \$a }',
113 code => '$x = f(1,2)',
114 },
e800e134
DM
115 'call::sub::args3_ret3' => {
116 desc => 'function call with 3 local lex vars and 3 return values',
117 setup => 'my @a; sub f { my ($a, $b, $c) = @_; $a+$b, $c, 1 }',
118 code => '@a = f(1,2,3)',
119 },
f7a874b8
DM
120 'call::sub::args3_ret3str' => {
121 desc => 'function call with 3 local lex vars and 3 string return values',
122 setup => 'my @a; sub f { my ($a, $b, $c) = @_; my @s = ("aa","bb","cc"); @s }',
123 code => '@a = f(1,2,3)',
124 },
125 'call::sub::args3_ret3temp' => {
126 desc => 'function call with 3 local lex vars and 3 TEMP return values',
127 setup => 'my @a; sub f { my ($a, $b, $c) = @_; 1..3 }',
128 code => '@a = f(1,2,3)',
129 },
130 'call::sub::recursive' => {
131 desc => 'basic recursive function call',
132 setup => 'my $x; sub f { my ($i) = @_; $i > 0 ? $i + f($i-1) : 0 }',
133 code => '$x = f(1)',
134 },
e800e134
DM
135
136 'call::goto::empty' => {
137 desc => 'goto &funtion with no args or body',
138 setup => 'sub f { goto &g } sub g {}',
139 code => 'f()',
140 },
141 'call::goto::args3' => {
142 desc => 'goto &funtion with 3 local lexical vars',
143 setup => 'sub f { goto &g } sub g { my ($a, $b, $c) = @_ }',
9e7973fa
DM
144 code => 'f(1,2,3)',
145 },
146
fedf30e1
DM
147
148 'expr::array::lex_1const_0' => {
149 desc => 'lexical $array[0]',
150 setup => 'my @a = (1)',
151 code => '$a[0]',
152 },
153 'expr::array::lex_1const_m1' => {
154 desc => 'lexical $array[-1]',
155 setup => 'my @a = (1)',
156 code => '$a[-1]',
157 },
158 'expr::array::lex_2const' => {
159 desc => 'lexical $array[const][const]',
160 setup => 'my @a = ([1,2])',
161 code => '$a[0][1]',
162 },
163 'expr::array::lex_2var' => {
164 desc => 'lexical $array[$i1][$i2]',
165 setup => 'my ($i1,$i2) = (0,1); my @a = ([1,2])',
166 code => '$a[$i1][$i2]',
167 },
168 'expr::array::ref_lex_2var' => {
169 desc => 'lexical $arrayref->[$i1][$i2]',
170 setup => 'my ($i1,$i2) = (0,1); my $r = [[1,2]]',
171 code => '$r->[$i1][$i2]',
172 },
173 'expr::array::ref_lex_3const' => {
174 desc => 'lexical $arrayref->[const][const][const]',
175 setup => 'my $r = [[[1,2]]]',
176 code => '$r->[0][0][0]',
177 },
178 'expr::array::ref_expr_lex_3const' => {
179 desc => '(lexical expr)->[const][const][const]',
180 setup => 'my $r = [[[1,2]]]',
92792a1c 181 code => '($r||0)->[0][0][0]',
fedf30e1
DM
182 },
183
184
185 'expr::array::pkg_1const_0' => {
186 desc => 'package $array[0]',
92792a1c 187 setup => '@a = (1)',
fedf30e1
DM
188 code => '$a[0]',
189 },
190 'expr::array::pkg_1const_m1' => {
191 desc => 'package $array[-1]',
92792a1c 192 setup => '@a = (1)',
fedf30e1
DM
193 code => '$a[-1]',
194 },
195 'expr::array::pkg_2const' => {
196 desc => 'package $array[const][const]',
92792a1c 197 setup => '@a = ([1,2])',
fedf30e1
DM
198 code => '$a[0][1]',
199 },
200 'expr::array::pkg_2var' => {
201 desc => 'package $array[$i1][$i2]',
92792a1c 202 setup => '($i1,$i2) = (0,1); @a = ([1,2])',
fedf30e1
DM
203 code => '$a[$i1][$i2]',
204 },
205 'expr::array::ref_pkg_2var' => {
206 desc => 'package $arrayref->[$i1][$i2]',
92792a1c 207 setup => '($i1,$i2) = (0,1); $r = [[1,2]]',
fedf30e1
DM
208 code => '$r->[$i1][$i2]',
209 },
210 'expr::array::ref_pkg_3const' => {
211 desc => 'package $arrayref->[const][const][const]',
92792a1c 212 setup => '$r = [[[1,2]]]',
fedf30e1
DM
213 code => '$r->[0][0][0]',
214 },
215 'expr::array::ref_expr_pkg_3const' => {
216 desc => '(package expr)->[const][const][const]',
92792a1c
DM
217 setup => '$r = [[[1,2]]]',
218 code => '($r||0)->[0][0][0]',
fedf30e1
DM
219 },
220
221
222 'expr::arrayhash::lex_3var' => {
223 desc => 'lexical $h{$k1}[$i]{$k2}',
224 setup => 'my ($i, $k1, $k2) = (0,"foo","bar");'
225 . 'my %h = (foo => [ { bar => 1 } ])',
226 code => '$h{$k1}[$i]{$k2}',
227 },
228 'expr::arrayhash::pkg_3var' => {
229 desc => 'package $h{$k1}[$i]{$k2}',
92792a1c
DM
230 setup => '($i, $k1, $k2) = (0,"foo","bar");'
231 . '%h = (foo => [ { bar => 1 } ])',
fedf30e1
DM
232 code => '$h{$k1}[$i]{$k2}',
233 },
234
fedf30e1
DM
235 'expr::hash::lex_1const' => {
236 desc => 'lexical $hash{const}',
237 setup => 'my %h = ("foo" => 1)',
238 code => '$h{foo}',
239 },
240 'expr::hash::lex_2const' => {
241 desc => 'lexical $hash{const}{const}',
242 setup => 'my %h = (foo => { bar => 1 })',
243 code => '$h{foo}{bar}',
244 },
245 'expr::hash::lex_2var' => {
246 desc => 'lexical $hash{$k1}{$k2}',
247 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 })',
248 code => '$h{$k1}{$k2}',
249 },
250 'expr::hash::ref_lex_2var' => {
251 desc => 'lexical $hashref->{$k1}{$k2}',
252 setup => 'my ($k1,$k2) = qw(foo bar); my $r = {$k1 => { $k2 => 1 }}',
253 code => '$r->{$k1}{$k2}',
254 },
255 'expr::hash::ref_lex_3const' => {
256 desc => 'lexical $hashref->{const}{const}{const}',
257 setup => 'my $r = {foo => { bar => { baz => 1 }}}',
258 code => '$r->{foo}{bar}{baz}',
259 },
260 'expr::hash::ref_expr_lex_3const' => {
261 desc => '(lexical expr)->{const}{const}{const}',
262 setup => 'my $r = {foo => { bar => { baz => 1 }}}',
92792a1c 263 code => '($r||0)->{foo}{bar}{baz}',
fedf30e1
DM
264 },
265
266
267 'expr::hash::pkg_1const' => {
268 desc => 'package $hash{const}',
92792a1c 269 setup => '%h = ("foo" => 1)',
fedf30e1
DM
270 code => '$h{foo}',
271 },
272 'expr::hash::pkg_2const' => {
273 desc => 'package $hash{const}{const}',
92792a1c 274 setup => '%h = (foo => { bar => 1 })',
fedf30e1
DM
275 code => '$h{foo}{bar}',
276 },
277 'expr::hash::pkg_2var' => {
278 desc => 'package $hash{$k1}{$k2}',
92792a1c 279 setup => '($k1,$k2) = qw(foo bar); %h = ($k1 => { $k2 => 1 })',
fedf30e1
DM
280 code => '$h{$k1}{$k2}',
281 },
282 'expr::hash::ref_pkg_2var' => {
283 desc => 'package $hashref->{$k1}{$k2}',
92792a1c 284 setup => '($k1,$k2) = qw(foo bar); $r = {$k1 => { $k2 => 1 }}',
fedf30e1
DM
285 code => '$r->{$k1}{$k2}',
286 },
287 'expr::hash::ref_pkg_3const' => {
288 desc => 'package $hashref->{const}{const}{const}',
92792a1c 289 setup => '$r = {foo => { bar => { baz => 1 }}}',
fedf30e1
DM
290 code => '$r->{foo}{bar}{baz}',
291 },
292 'expr::hash::ref_expr_pkg_3const' => {
293 desc => '(package expr)->{const}{const}{const}',
92792a1c
DM
294 setup => '$r = {foo => { bar => { baz => 1 }}}',
295 code => '($r||0)->{foo}{bar}{baz}',
fedf30e1
DM
296 },
297
298
299 'expr::hash::exists_lex_2var' => {
300 desc => 'lexical exists $hash{$k1}{$k2}',
301 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 });',
302 code => 'exists $h{$k1}{$k2}',
303 },
304 'expr::hash::delete_lex_2var' => {
305 desc => 'lexical delete $hash{$k1}{$k2}',
306 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 });',
307 code => 'delete $h{$k1}{$k2}',
308 },
309
310
a5f48505
DM
311 # list assign, OP_AASSIGN
312
313
314 # (....) = ()
315
316 'expr::aassign::ma_empty' => {
317 desc => 'my array assigned empty',
318 setup => '',
319 code => 'my @a = ()',
320 },
321 'expr::aassign::lax_empty' => {
322 desc => 'non-empty lexical array assigned empty',
323 setup => 'my @a = 1..3;',
324 code => '@a = ()',
325 },
326 'expr::aassign::llax_empty' => {
327 desc => 'non-empty lexical var and array assigned empty',
328 setup => 'my ($x, @a) = 1..4;',
329 code => '($x, @a) = ()',
330 },
8b0c3377
DM
331 'expr::aassign::mh_empty' => {
332 desc => 'my hash assigned empty',
333 setup => '',
334 code => 'my %h = ()',
335 },
336 'expr::aassign::lhx_empty' => {
337 desc => 'non-empty lexical hash assigned empty',
338 setup => 'my %h = 1..4;',
339 code => '%h = ()',
340 },
341 'expr::aassign::llhx_empty' => {
342 desc => 'non-empty lexical var and hash assigned empty',
343 setup => 'my ($x, %h) = 1..5;',
344 code => '($x, %h) = ()',
345 },
a5f48505
DM
346 'expr::aassign::3m_empty' => {
347 desc => 'three my vars assigned empty',
348 setup => '',
349 code => 'my ($x,$y,$z) = ()',
350 },
351 'expr::aassign::3l_empty' => {
352 desc => 'three lexical vars assigned empty',
353 setup => 'my ($x,$y,$z)',
354 code => '($x,$y,$z) = ()',
355 },
e03e82a0
DM
356 'expr::aassign::3lref_empty' => {
357 desc => 'three lexical ref vars assigned empty',
358 setup => 'my ($x,$y,$z); my $r = []; ',
359 code => '($x,$y,$z) = ($r,$r,$r); ($x,$y,$z) = ()',
360 },
a5f48505
DM
361 'expr::aassign::pa_empty' => {
362 desc => 'package array assigned empty',
363 setup => '',
364 code => '@a = ()',
365 },
366 'expr::aassign::pax_empty' => {
367 desc => 'non-empty package array assigned empty',
368 setup => '@a = (1,2,3)',
369 code => '@a = ()',
370 },
371 'expr::aassign::3p_empty' => {
372 desc => 'three package vars assigned empty',
373 setup => '($x,$y,$z) = 1..3;',
374 code => '($x,$y,$z) = ()',
375 },
376
377 # (....) = (1,2,3)
378
379 'expr::aassign::ma_3c' => {
380 desc => 'my array assigned 3 consts',
381 setup => '',
382 code => 'my @a = (1,2,3)',
383 },
384 'expr::aassign::lax_3c' => {
385 desc => 'non-empty lexical array assigned 3 consts',
386 setup => 'my @a = 1..3;',
387 code => '@a = (1,2,3)',
388 },
389 'expr::aassign::llax_3c' => {
390 desc => 'non-empty lexical var and array assigned 3 consts',
391 setup => 'my ($x, @a) = 1..4;',
392 code => '($x, @a) = (1,2,3)',
393 },
8b0c3377
DM
394 'expr::aassign::mh_4c' => {
395 desc => 'my hash assigned 4 consts',
396 setup => '',
397 code => 'my %h = qw(a 1 b 2)',
398 },
399 'expr::aassign::lhx_4c' => {
400 desc => 'non-empty lexical hash assigned 4 consts',
401 setup => 'my %h = qw(a 1 b 2);',
402 code => '%h = qw(c 3 d 4)',
403 },
404 'expr::aassign::llhx_5c' => {
405 desc => 'non-empty lexical var and array assigned 5 consts',
406 setup => 'my ($x, %h) = (1, qw(a 1 b 2));',
407 code => '($x, %h) = (10, qw(c 3 d 4))',
408 },
a5f48505
DM
409 'expr::aassign::3m_3c' => {
410 desc => 'three my vars assigned 3 consts',
411 setup => '',
412 code => 'my ($x,$y,$z) = (1,2,3)',
413 },
414 'expr::aassign::3l_3c' => {
415 desc => 'three lexical vars assigned 3 consts',
416 setup => 'my ($x,$y,$z)',
417 code => '($x,$y,$z) = (1,2,3)',
418 },
419 'expr::aassign::pa_3c' => {
420 desc => 'package array assigned 3 consts',
421 setup => '',
422 code => '@a = (1,2,3)',
423 },
424 'expr::aassign::pax_3c' => {
425 desc => 'non-empty package array assigned 3 consts',
426 setup => '@a = (1,2,3)',
427 code => '@a = (1,2,3)',
428 },
429 'expr::aassign::3p_3c' => {
430 desc => 'three package vars assigned 3 consts',
431 setup => '($x,$y,$z) = 1..3;',
432 code => '($x,$y,$z) = (1,2,3)',
433 },
434
435 # (....) = @lexical
436
437 'expr::aassign::ma_la' => {
438 desc => 'my array assigned lexical array',
439 setup => 'my @init = 1..3;',
440 code => 'my @a = @init',
441 },
442 'expr::aassign::lax_la' => {
443 desc => 'non-empty lexical array assigned lexical array',
444 setup => 'my @init = 1..3; my @a = 1..3;',
445 code => '@a = @init',
446 },
447 'expr::aassign::llax_la' => {
448 desc => 'non-empty lexical var and array assigned lexical array',
449 setup => 'my @init = 1..3; my ($x, @a) = 1..4;',
450 code => '($x, @a) = @init',
451 },
452 'expr::aassign::3m_la' => {
453 desc => 'three my vars assigned lexical array',
454 setup => 'my @init = 1..3;',
455 code => 'my ($x,$y,$z) = @init',
456 },
457 'expr::aassign::3l_la' => {
458 desc => 'three lexical vars assigned lexical array',
459 setup => 'my @init = 1..3; my ($x,$y,$z)',
460 code => '($x,$y,$z) = @init',
461 },
462 'expr::aassign::pa_la' => {
463 desc => 'package array assigned lexical array',
464 setup => 'my @init = 1..3;',
465 code => '@a = @init',
466 },
467 'expr::aassign::pax_la' => {
468 desc => 'non-empty package array assigned lexical array',
469 setup => 'my @init = 1..3; @a = @init',
470 code => '@a = @init',
471 },
472 'expr::aassign::3p_la' => {
473 desc => 'three package vars assigned lexical array',
474 setup => 'my @init = 1..3; ($x,$y,$z) = 1..3;',
475 code => '($x,$y,$z) = @init',
476 },
477
478 # (....) = @package
479
480 'expr::aassign::ma_pa' => {
481 desc => 'my array assigned package array',
482 setup => '@init = 1..3;',
483 code => 'my @a = @init',
484 },
485 'expr::aassign::lax_pa' => {
486 desc => 'non-empty lexical array assigned package array',
487 setup => '@init = 1..3; my @a = 1..3;',
488 code => '@a = @init',
489 },
490 'expr::aassign::llax_pa' => {
491 desc => 'non-empty lexical var and array assigned package array',
492 setup => '@init = 1..3; my ($x, @a) = 1..4;',
493 code => '($x, @a) = @init',
494 },
495 'expr::aassign::3m_pa' => {
496 desc => 'three my vars assigned package array',
497 setup => '@init = 1..3;',
498 code => 'my ($x,$y,$z) = @init',
499 },
500 'expr::aassign::3l_pa' => {
501 desc => 'three lexical vars assigned package array',
502 setup => '@init = 1..3; my ($x,$y,$z)',
503 code => '($x,$y,$z) = @init',
504 },
505 'expr::aassign::pa_pa' => {
506 desc => 'package array assigned package array',
507 setup => '@init = 1..3;',
508 code => '@a = @init',
509 },
510 'expr::aassign::pax_pa' => {
511 desc => 'non-empty package array assigned package array',
512 setup => '@init = 1..3; @a = @init',
513 code => '@a = @init',
514 },
515 'expr::aassign::3p_pa' => {
516 desc => 'three package vars assigned package array',
517 setup => '@init = 1..3; ($x,$y,$z) = 1..3;',
518 code => '($x,$y,$z) = @init',
519 },
520
521 # (....) = @_;
522
523 'expr::aassign::ma_defary' => {
524 desc => 'my array assigned @_',
525 setup => '@_ = 1..3;',
526 code => 'my @a = @_',
527 },
528 'expr::aassign::lax_defary' => {
529 desc => 'non-empty lexical array assigned @_',
530 setup => '@_ = 1..3; my @a = 1..3;',
531 code => '@a = @_',
532 },
533 'expr::aassign::llax_defary' => {
534 desc => 'non-empty lexical var and array assigned @_',
535 setup => '@_ = 1..3; my ($x, @a) = 1..4;',
536 code => '($x, @a) = @_',
537 },
538 'expr::aassign::3m_defary' => {
539 desc => 'three my vars assigned @_',
540 setup => '@_ = 1..3;',
541 code => 'my ($x,$y,$z) = @_',
542 },
543 'expr::aassign::3l_defary' => {
544 desc => 'three lexical vars assigned @_',
545 setup => '@_ = 1..3; my ($x,$y,$z)',
546 code => '($x,$y,$z) = @_',
547 },
548 'expr::aassign::pa_defary' => {
549 desc => 'package array assigned @_',
550 setup => '@_ = 1..3;',
551 code => '@a = @_',
552 },
553 'expr::aassign::pax_defary' => {
554 desc => 'non-empty package array assigned @_',
555 setup => '@_ = 1..3; @a = @_',
556 code => '@a = @_',
557 },
558 'expr::aassign::3p_defary' => {
559 desc => 'three package vars assigned @_',
560 setup => '@_ = 1..3; ($x,$y,$z) = 1..3;',
561 code => '($x,$y,$z) = @_',
562 },
563
564
565 # (....) = ($lex1,$lex2,$lex3);
566
567 'expr::aassign::ma_3l' => {
568 desc => 'my array assigned lexicals',
569 setup => 'my ($v1,$v2,$v3) = 1..3;',
570 code => 'my @a = ($v1,$v2,$v3)',
571 },
572 'expr::aassign::lax_3l' => {
573 desc => 'non-empty lexical array assigned lexicals',
574 setup => 'my ($v1,$v2,$v3) = 1..3; my @a = 1..3;',
575 code => '@a = ($v1,$v2,$v3)',
576 },
577 'expr::aassign::llax_3l' => {
578 desc => 'non-empty lexical var and array assigned lexicals',
579 setup => 'my ($v1,$v2,$v3) = 1..3; my ($x, @a) = 1..4;',
580 code => '($x, @a) = ($v1,$v2,$v3)',
581 },
582 'expr::aassign::3m_3l' => {
583 desc => 'three my vars assigned lexicals',
584 setup => 'my ($v1,$v2,$v3) = 1..3;',
585 code => 'my ($x,$y,$z) = ($v1,$v2,$v3)',
586 },
587 'expr::aassign::3l_3l' => {
588 desc => 'three lexical vars assigned lexicals',
589 setup => 'my ($v1,$v2,$v3) = 1..3; my ($x,$y,$z)',
590 code => '($x,$y,$z) = ($v1,$v2,$v3)',
591 },
592 'expr::aassign::pa_3l' => {
593 desc => 'package array assigned lexicals',
594 setup => 'my ($v1,$v2,$v3) = 1..3;',
595 code => '@a = ($v1,$v2,$v3)',
596 },
597 'expr::aassign::pax_3l' => {
598 desc => 'non-empty package array assigned lexicals',
599 setup => 'my ($v1,$v2,$v3) = 1..3; @a = @_',
600 code => '@a = ($v1,$v2,$v3)',
601 },
602 'expr::aassign::3p_3l' => {
603 desc => 'three package vars assigned lexicals',
604 setup => 'my ($v1,$v2,$v3) = 1..3; ($x,$y,$z) = 1..3;',
605 code => '($x,$y,$z) = ($v1,$v2,$v3)',
606 },
607
608
609 # (....) = ($pkg1,$pkg2,$pkg3);
610
611 'expr::aassign::ma_3p' => {
612 desc => 'my array assigned 3 package vars',
613 setup => '($v1,$v2,$v3) = 1..3;',
614 code => 'my @a = ($v1,$v2,$v3)',
615 },
616 'expr::aassign::lax_3p' => {
617 desc => 'non-empty lexical array assigned 3 package vars',
618 setup => '($v1,$v2,$v3) = 1..3; my @a = 1..3;',
619 code => '@a = ($v1,$v2,$v3)',
620 },
621 'expr::aassign::llax_3p' => {
622 desc => 'non-empty lexical var and array assigned 3 package vars',
623 setup => '($v1,$v2,$v3) = 1..3; my ($x, @a) = 1..4;',
624 code => '($x, @a) = ($v1,$v2,$v3)',
625 },
626 'expr::aassign::3m_3p' => {
627 desc => 'three my vars assigned 3 package vars',
628 setup => '($v1,$v2,$v3) = 1..3;',
629 code => 'my ($x,$y,$z) = ($v1,$v2,$v3)',
630 },
631 'expr::aassign::3l_3p' => {
632 desc => 'three lexical vars assigned 3 package vars',
633 setup => '($v1,$v2,$v3) = 1..3; my ($x,$y,$z)',
634 code => '($x,$y,$z) = ($v1,$v2,$v3)',
635 },
636 'expr::aassign::pa_3p' => {
637 desc => 'package array assigned 3 package vars',
638 setup => '($v1,$v2,$v3) = 1..3;',
639 code => '@a = ($v1,$v2,$v3)',
640 },
641 'expr::aassign::pax_3p' => {
642 desc => 'non-empty package array assigned 3 package vars',
643 setup => '($v1,$v2,$v3) = 1..3; @a = @_',
644 code => '@a = ($v1,$v2,$v3)',
645 },
646 'expr::aassign::3p_3p' => {
647 desc => 'three package vars assigned 3 package vars',
648 setup => '($v1,$v2,$v3) = 1..3; ($x,$y,$z) = 1..3;',
649 code => '($x,$y,$z) = ($v1,$v2,$v3)',
650 },
651
652
653 # (....) = (1,2,$shared);
654
655 'expr::aassign::llax_2c1s' => {
656 desc => 'non-empty lexical var and array assigned 2 consts and 1 shared var',
657 setup => 'my ($x, @a) = 1..4;',
658 code => '($x, @a) = (1,2,$x)',
659 },
660 'expr::aassign::3l_2c1s' => {
661 desc => 'three lexical vars assigned 2 consts and 1 shared var',
662 setup => 'my ($x,$y,$z) = 1..3;',
663 code => '($x,$y,$z) = (1,2,$x)',
664 },
665 'expr::aassign::3p_2c1s' => {
666 desc => 'three package vars assigned 2 consts and 1 shared var',
667 setup => '($x,$y,$z) = 1..3;',
668 code => '($x,$y,$z) = (1,2,$x)',
669 },
670
671
672 # ($a,$b) = ($b,$a);
673
674 'expr::aassign::2l_swap' => {
675 desc => 'swap two lexical vars',
676 setup => 'my ($a,$b) = (1,2)',
677 code => '($a,$b) = ($b,$a)',
678 },
679 'expr::aassign::2p_swap' => {
680 desc => 'swap two package vars',
681 setup => '($a,$b) = (1,2)',
682 code => '($a,$b) = ($b,$a)',
683 },
684 'expr::aassign::2laelem_swap' => {
685 desc => 'swap two lexical vars',
686 setup => 'my @a = (1,2)',
687 code => '($a[0],$a[1]) = ($a[1],$a[0])',
688 },
689
690 # misc list assign
691
692 'expr::aassign::5l_4l1s' => {
693 desc => 'long list of lexical vars, 1 shared',
694 setup => 'my ($a,$b,$c,$d,$e) = 1..5',
695 code => '($a,$b,$c,$d,$e) = ($a,$a,$c,$d,$e)',
696 },
697
698 'expr::aassign::5p_4p1s' => {
699 desc => 'long list of package vars, 1 shared',
700 setup => '($a,$b,$c,$d,$e) = 1..5',
701 code => '($a,$b,$c,$d,$e) = ($a,$a,$c,$d,$e)',
702 },
703 'expr::aassign::5l_defary' => {
704 desc => 'long list of lexical vars to assign @_ to',
705 setup => '@_ = 1..5',
706 code => 'my ($a,$b,$c,$d,$e) = @_',
707 },
708 'expr::aassign::5l1la_defary' => {
709 desc => 'long list of lexical vars plus long slurp to assign @_ to',
710 setup => '@_ = 1..20',
711 code => 'my ($a,$b,$c,$d,$e,@rest) = @_',
712 },
808ce557
DM
713 'expr::aassign::1l_2l' => {
714 desc => 'single lexical LHS',
715 setup => 'my $x = 1;',
716 code => '(undef,$x) = ($x,$x)',
717 },
718 'expr::aassign::2l_1l' => {
719 desc => 'single lexical RHS',
720 setup => 'my $x = 1;',
9ae0115f
DM
721 code => '($x,$x) = ($x)',
722 },
723 'expr::aassign::2l_1ul' => {
724 desc => 'undef and single lexical RHS',
725 setup => 'my $x = 1;',
808ce557
DM
726 code => '($x,$x) = (undef, $x)',
727 },
a5f48505 728
90303eef
DM
729 'expr::aassign::2list_lex' => {
730 desc => 'lexical ($x, $y) = (1, 2)',
731 setup => 'my ($x, $y)',
732 code => '($x, $y) = (1, 2)',
733 },
734
d24e3eb1
DM
735 'expr::aassign::lex_rv' => {
736 desc => 'lexical ($ref1, $ref2) = ($ref3, $ref4)',
737 setup => 'my ($r1, $r2, $r3, $r4);
738 ($r1, $r2) = (($r3, $r4) = ([], []));',
739 code => '($r1, $r2) = ($r3, $r4)',
740 },
741
742 'expr::aassign::lex_rv1' => {
743 desc => 'lexical ($ref1, $ref2) = ($ref3, $ref4) where ref1,2 are freed',
744 setup => 'my ($r1, $r2);',
745 code => '($r1, $r2) = ([], []);',
746 },
747
8b0c3377
DM
748 # array assign of strings
749
750 'expr::aassign::la_3s' => {
751 desc => 'assign 3 strings to empty lexical array',
752 setup => 'my @a',
753 code => '@a = (); @a = qw(abc defg hijkl);',
754 },
755 'expr::aassign::la_3ts' => {
756 desc => 'assign 3 temp strings to empty lexical array',
757 setup => 'my @a',
758 code => '@a = (); @a = map $_, qw(abc defg hijkl);',
759 },
760 'expr::aassign::lan_3s' => {
761 desc => 'assign 3 strings to non-empty lexical array',
762 setup => 'my @a = qw(abc defg hijkl)',
763 code => '@a = qw(abc defg hijkl);',
764 },
765 'expr::aassign::lan_3ts' => {
766 desc => 'assign 3 temp strings to non-empty lexical array',
767 setup => 'my @a = qw(abc defg hijkl)',
768 code => '@a = map $_, qw(abc defg hijkl);',
769 },
770
771 # hash assign of strings
772
773 'expr::aassign::lh_2s' => {
774 desc => 'assign 2 strings to empty lexical hash',
775 setup => 'my %h',
776 code => '%h = (); %h = qw(k1 abc k2 defg);',
777 },
778 'expr::aassign::lh_2ts' => {
779 desc => 'assign 2 temp strings to empty lexical hash',
780 setup => 'my %h',
781 code => '%h = (); %h = map $_, qw(k1 abc k2 defg);',
782 },
783 'expr::aassign::lhn_2s' => {
784 desc => 'assign 2 strings to non-empty lexical hash',
785 setup => 'my %h = qw(k1 abc k2 defg);',
786 code => '%h = qw(k1 abc k2 defg);',
787 },
788 'expr::aassign::lhn_2ts' => {
789 desc => 'assign 2 temp strings to non-empty lexical hash',
790 setup => 'my %h = qw(k1 abc k2 defg);',
791 code => '%h = map $_, qw(k1 abc k2 defg);',
792 },
793
a5f48505 794
230ee21f
DM
795 'expr::arith::add_lex_ii' => {
796 desc => 'add two integers and assign to a lexical var',
797 setup => 'my ($x,$y,$z) = 1..3;',
798 code => '$z = $x + $y',
799 },
800 'expr::arith::add_pkg_ii' => {
801 desc => 'add two integers and assign to a package var',
802 setup => 'my ($x,$y) = 1..2; $z = 3;',
803 code => '$z = $x + $y',
804 },
805 'expr::arith::add_lex_nn' => {
806 desc => 'add two NVs and assign to a lexical var',
807 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
808 code => '$z = $x + $y',
809 },
810 'expr::arith::add_pkg_nn' => {
811 desc => 'add two NVs and assign to a package var',
812 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
813 code => '$z = $x + $y',
814 },
815 'expr::arith::add_lex_ni' => {
816 desc => 'add an int and an NV and assign to a lexical var',
817 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
818 code => '$z = $x + $y',
819 },
820 'expr::arith::add_pkg_ni' => {
821 desc => 'add an int and an NV and assign to a package var',
822 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
823 code => '$z = $x + $y',
824 },
80e5abf2
DM
825 'expr::arith::add_lex_ss' => {
826 desc => 'add two short strings and assign to a lexical var',
827 setup => 'my ($x,$y,$z) = ("1", "2", 1);',
828 code => '$z = $x + $y; $x = "1"; ',
829 },
830
831 'expr::arith::add_lex_ll' => {
832 desc => 'add two long strings and assign to a lexical var',
833 setup => 'my ($x,$y,$z) = ("12345", "23456", 1);',
834 code => '$z = $x + $y; $x = "12345"; ',
835 },
230ee21f
DM
836
837 'expr::arith::sub_lex_ii' => {
838 desc => 'subtract two integers and assign to a lexical var',
839 setup => 'my ($x,$y,$z) = 1..3;',
840 code => '$z = $x - $y',
841 },
842 'expr::arith::sub_pkg_ii' => {
843 desc => 'subtract two integers and assign to a package var',
844 setup => 'my ($x,$y) = 1..2; $z = 3;',
845 code => '$z = $x - $y',
846 },
847 'expr::arith::sub_lex_nn' => {
848 desc => 'subtract two NVs and assign to a lexical var',
849 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
850 code => '$z = $x - $y',
851 },
852 'expr::arith::sub_pkg_nn' => {
853 desc => 'subtract two NVs and assign to a package var',
854 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
855 code => '$z = $x - $y',
856 },
857 'expr::arith::sub_lex_ni' => {
858 desc => 'subtract an int and an NV and assign to a lexical var',
859 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
860 code => '$z = $x - $y',
861 },
862 'expr::arith::sub_pkg_ni' => {
863 desc => 'subtract an int and an NV and assign to a package var',
864 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
865 code => '$z = $x - $y',
866 },
867
868 'expr::arith::mult_lex_ii' => {
869 desc => 'multiply two integers and assign to a lexical var',
870 setup => 'my ($x,$y,$z) = 1..3;',
871 code => '$z = $x * $y',
872 },
873 'expr::arith::mult_pkg_ii' => {
874 desc => 'multiply two integers and assign to a package var',
875 setup => 'my ($x,$y) = 1..2; $z = 3;',
876 code => '$z = $x * $y',
877 },
878 'expr::arith::mult_lex_nn' => {
879 desc => 'multiply two NVs and assign to a lexical var',
880 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
881 code => '$z = $x * $y',
882 },
883 'expr::arith::mult_pkg_nn' => {
884 desc => 'multiply two NVs and assign to a package var',
885 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
886 code => '$z = $x * $y',
887 },
888 'expr::arith::mult_lex_ni' => {
889 desc => 'multiply an int and an NV and assign to a lexical var',
890 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
891 code => '$z = $x * $y',
892 },
893 'expr::arith::mult_pkg_ni' => {
894 desc => 'multiply an int and an NV and assign to a package var',
895 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
896 code => '$z = $x * $y',
897 },
898
4c2c3128
DM
899 'expr::arith::preinc' => {
900 desc => '++$x',
901 setup => 'my $x = 1;',
902 code => '++$x',
903 },
904 'expr::arith::predec' => {
905 desc => '--$x',
906 setup => 'my $x = 1;',
907 code => '--$x',
908 },
909 'expr::arith::postinc' => {
910 desc => '$x++',
911 setup => 'my $x = 1; my $y',
912 code => '$y = $x++', # scalar context so not optimised to ++$x
913 },
914 'expr::arith::postdec' => {
915 desc => '$x--',
916 setup => 'my $x = 1; my $y',
917 code => '$y = $x--', # scalar context so not optimised to --$x
b52de964
DM
918 },
919
84721d61 920
5012eebe 921
90303eef
DM
922 # scalar assign, OP_SASSIGN
923
924
925 'expr::sassign::scalar_lex_int' => {
926 desc => 'lexical $x = 1',
927 setup => 'my $x',
928 code => '$x = 1',
929 },
930 'expr::sassign::scalar_lex_str' => {
931 desc => 'lexical $x = "abc"',
932 setup => 'my $x',
933 code => '$x = "abc"',
934 },
935 'expr::sassign::scalar_lex_strint' => {
936 desc => 'lexical $x = 1 where $x was previously a string',
937 setup => 'my $x = "abc"',
938 code => '$x = 1',
939 },
940 'expr::sassign::scalar_lex_intstr' => {
941 desc => 'lexical $x = "abc" where $x was previously an int',
942 setup => 'my $x = 1;',
943 code => '$x = "abc"',
944 },
a0833292
DM
945 'expr::sassign::lex_rv' => {
946 desc => 'lexical $ref1 = $ref2;',
947 setup => 'my $r1 = []; my $r = $r1;',
948 code => '$r = $r1;',
949 },
950 'expr::sassign::lex_rv1' => {
951 desc => 'lexical $ref1 = $ref2; where $$ref1 gets freed',
952 setup => 'my $r1 = []; my $r',
953 code => '$r = []; $r = $r1;',
954 },
90303eef
DM
955
956
957
d670485e
DM
958 # using a const string as second arg to index triggers using FBM.
959 # the FBM matcher special-cases 1,2-byte strings.
960 #
961 'func::index::short_const1' => {
962 desc => 'index of a short string against a 1 char const substr',
963 setup => 'my $x = "aaaab"',
964 code => 'index $x, "b"',
965 },
966 'func::index::long_const1' => {
967 desc => 'index of a long string against a 1 char const substr',
968 setup => 'my $x = "a" x 1000 . "b"',
969 code => 'index $x, "b"',
970 },
971 'func::index::short_const2aabc_bc' => {
972 desc => 'index of a short string against a 2 char const substr',
973 setup => 'my $x = "aaaabc"',
974 code => 'index $x, "bc"',
975 },
976 'func::index::long_const2aabc_bc' => {
977 desc => 'index of a long string against a 2 char const substr',
978 setup => 'my $x = "a" x 1000 . "bc"',
979 code => 'index $x, "bc"',
980 },
981 'func::index::long_const2aa_ab' => {
982 desc => 'index of a long string aaa.. against const substr "ab"',
983 setup => 'my $x = "a" x 1000',
984 code => 'index $x, "ab"',
985 },
986 'func::index::long_const2bb_ab' => {
987 desc => 'index of a long string bbb.. against const substr "ab"',
988 setup => 'my $x = "b" x 1000',
989 code => 'index $x, "ab"',
990 },
991 'func::index::long_const2aa_bb' => {
992 desc => 'index of a long string aaa.. against const substr "bb"',
993 setup => 'my $x = "a" x 1000',
994 code => 'index $x, "bb"',
995 },
996 # this one is designed to be pathological
997 'func::index::long_const2ab_aa' => {
998 desc => 'index of a long string abab.. against const substr "aa"',
999 setup => 'my $x = "ab" x 500',
1000 code => 'index $x, "aa"',
1001 },
1002 # near misses with gaps, 1st letter
1003 'func::index::long_const2aaxx_xy' => {
1004 desc => 'index of a long string with "xx"s against const substr "xy"',
1005 setup => 'my $x = "aaaaaaaaxx" x 100',
1006 code => 'index $x, "xy"',
1007 },
1008 # near misses with gaps, 2nd letter
1009 'func::index::long_const2aayy_xy' => {
1010 desc => 'index of a long string with "yy"s against const substr "xy"',
1011 setup => 'my $x = "aaaaaaaayy" x 100',
1012 code => 'index $x, "xy"',
1013 },
1014 # near misses with gaps, duplicate letter
1015 'func::index::long_const2aaxy_xx' => {
1016 desc => 'index of a long string with "xy"s against const substr "xx"',
1017 setup => 'my $x = "aaaaaaaaxy" x 100',
1018 code => 'index $x, "xx"',
1019 },
1020 # alternating near misses with gaps
1021 'func::index::long_const2aaxxaayy_xy' => {
1022 desc => 'index of a long string with "xx/yy"s against const substr "xy"',
1023 setup => 'my $x = "aaaaaaaaxxbbbbbbbbyy" x 50',
1024 code => 'index $x, "xy"',
1025 },
1026 'func::index::short_const3aabcd_bcd' => {
1027 desc => 'index of a short string against a 3 char const substr',
1028 setup => 'my $x = "aaaabcd"',
1029 code => 'index $x, "bcd"',
1030 },
1031 'func::index::long_const3aabcd_bcd' => {
1032 desc => 'index of a long string against a 3 char const substr',
1033 setup => 'my $x = "a" x 1000 . "bcd"',
1034 code => 'index $x, "bcd"',
1035 },
1036 'func::index::long_const3ab_abc' => {
1037 desc => 'index of a long string of "ab"s against a 3 char const substr "abc"',
1038 setup => 'my $x = "ab" x 500',
1039 code => 'index $x, "abc"',
1040 },
1041 'func::index::long_const3bc_abc' => {
1042 desc => 'index of a long string of "bc"s against a 3 char const substr "abc"',
1043 setup => 'my $x = "bc" x 500',
1044 code => 'index $x, "abc"',
1045 },
1046 'func::index::utf8_position_1' => {
1047 desc => 'index of a utf8 string, matching at position 1',
1048 setup => 'my $x = "abc". chr(0x100); chop $x',
1049 code => 'index $x, "b"',
1050 },
1051
1052
1053
84721d61
DM
1054 'func::sort::num' => {
1055 desc => 'plain numeric sort',
1056 setup => 'my (@a, @b); @a = reverse 1..10;',
1057 code => '@b = sort { $a <=> $b } @a',
1058 },
1059 'func::sort::num_block' => {
1060 desc => 'codeblock numeric sort',
1061 setup => 'my (@a, @b); @a = reverse 1..10;',
1062 code => '@b = sort { $a + 1 <=> $b + 1 } @a',
1063 },
1064 'func::sort::num_fn' => {
1065 desc => 'function numeric sort',
1066 setup => 'sub f { $a + 1 <=> $b + 1 } my (@a, @b); @a = reverse 1..10;',
1067 code => '@b = sort f @a',
1068 },
1069 'func::sort::str' => {
1070 desc => 'plain string sort',
1071 setup => 'my (@a, @b); @a = reverse "a".."j";',
1072 code => '@b = sort { $a cmp $b } @a',
1073 },
1074 'func::sort::str_block' => {
1075 desc => 'codeblock string sort',
1076 setup => 'my (@a, @b); @a = reverse "a".."j";',
1077 code => '@b = sort { ($a . "") cmp ($b . "") } @a',
1078 },
1079 'func::sort::str_fn' => {
1080 desc => 'function string sort',
1081 setup => 'sub f { ($a . "") cmp ($b . "") } my (@a, @b); @a = reverse "a".."j";',
1082 code => '@b = sort f @a',
1083 },
1084
1085 'func::sort::num_inplace' => {
1086 desc => 'plain numeric sort in-place',
1087 setup => 'my @a = reverse 1..10;',
1088 code => '@a = sort { $a <=> $b } @a',
1089 },
1090 'func::sort::num_block_inplace' => {
1091 desc => 'codeblock numeric sort in-place',
1092 setup => 'my @a = reverse 1..10;',
1093 code => '@a = sort { $a + 1 <=> $b + 1 } @a',
1094 },
1095 'func::sort::num_fn_inplace' => {
1096 desc => 'function numeric sort in-place',
1097 setup => 'sub f { $a + 1 <=> $b + 1 } my @a = reverse 1..10;',
1098 code => '@a = sort f @a',
1099 },
1100 'func::sort::str_inplace' => {
1101 desc => 'plain string sort in-place',
1102 setup => 'my @a = reverse "a".."j";',
1103 code => '@a = sort { $a cmp $b } @a',
1104 },
1105 'func::sort::str_block_inplace' => {
1106 desc => 'codeblock string sort in-place',
1107 setup => 'my @a = reverse "a".."j";',
1108 code => '@a = sort { ($a . "") cmp ($b . "") } @a',
1109 },
1110 'func::sort::str_fn_inplace' => {
1111 desc => 'function string sort in-place',
1112 setup => 'sub f { ($a . "") cmp ($b . "") } my @a = reverse "a".."j";',
1113 code => '@a = sort f @a',
1114 },
1115
1116
5012eebe
DM
1117 'func::split::vars' => {
1118 desc => 'split into two lexical vars',
1119 setup => 'my $s = "abc:def";',
1120 code => 'my ($x, $y) = split /:/, $s, 2;',
1121 },
1122
1123 'func::split::array' => {
1124 desc => 'split into a lexical array',
1125 setup => 'my @a; my $s = "abc:def";',
1126 code => '@a = split /:/, $s, 2;',
1127 },
5012eebe
DM
1128 'func::split::myarray' => {
1129 desc => 'split into a lexical array declared in the assign',
1130 setup => 'my $s = "abc:def";',
1131 code => 'my @a = split /:/, $s, 2;',
1132 },
692044df
DM
1133 'func::split::arrayexpr' => {
1134 desc => 'split into an @{$expr} ',
1135 setup => 'my $s = "abc:def"; my $r = []',
1136 code => '@$r = split /:/, $s, 2;',
1137 },
47a8f19b
DM
1138 'func::split::arraylist' => {
1139 desc => 'split into an array with extra arg',
1140 setup => 'my @a; my $s = "abc:def";',
1141 code => '@a = (split(/:/, $s, 2), 1);',
1142 },
5012eebe
DM
1143
1144
aedeb7c2
DM
1145 'loop::block' => {
1146 desc => 'empty basic loop',
84721d61 1147 setup => '',
aedeb7c2
DM
1148 code => '{1;}',
1149 },
1150
1151 'loop::do' => {
1152 desc => 'basic do block',
1153 setup => 'my $x; my $y = 2;',
1154 code => '$x = do {1; $y}', # the ';' stops the do being optimised
1155 },
1156
1157 'loop::for::my_range1' => {
1158 desc => 'empty for loop with my var and 1 integer range',
1159 setup => '',
1160 code => 'for my $x (1..1) {}',
1161 },
1162 'loop::for::lex_range1' => {
1163 desc => 'empty for loop with lexical var and 1 integer range',
1164 setup => 'my $x;',
1165 code => 'for $x (1..1) {}',
1166 },
1167 'loop::for::pkg_range1' => {
1168 desc => 'empty for loop with package var and 1 integer range',
1169 setup => '$x = 1;',
1170 code => 'for $x (1..1) {}',
1171 },
1172 'loop::for::defsv_range1' => {
1173 desc => 'empty for loop with $_ and integer 1 range',
1174 setup => ';',
1175 code => 'for (1..1) {}',
1176 },
1177 'loop::for::my_range4' => {
1178 desc => 'empty for loop with my var and 4 integer range',
1179 setup => '',
1180 code => 'for my $x (1..4) {}',
1181 },
1182 'loop::for::lex_range4' => {
1183 desc => 'empty for loop with lexical var and 4 integer range',
1184 setup => 'my $x;',
1185 code => 'for $x (1..4) {}',
1186 },
1187 'loop::for::pkg_range4' => {
1188 desc => 'empty for loop with package var and 4 integer range',
1189 setup => '$x = 1;',
1190 code => 'for $x (1..4) {}',
1191 },
1192 'loop::for::defsv_range4' => {
1193 desc => 'empty for loop with $_ and integer 4 range',
1194 setup => ';',
1195 code => 'for (1..4) {}',
1196 },
4c2c3128 1197
aedeb7c2
DM
1198 'loop::for::my_list1' => {
1199 desc => 'empty for loop with my var and 1 integer list',
b52de964 1200 setup => '',
aedeb7c2
DM
1201 code => 'for my $x (1) {}',
1202 },
1203 'loop::for::lex_list1' => {
1204 desc => 'empty for loop with lexical var and 1 integer list',
1205 setup => 'my $x;',
1206 code => 'for $x (1) {}',
1207 },
1208 'loop::for::pkg_list1' => {
1209 desc => 'empty for loop with package var and 1 integer list',
1210 setup => '$x = 1;',
1211 code => 'for $x (1) {}',
1212 },
1213 'loop::for::defsv_list1' => {
1214 desc => 'empty for loop with $_ and integer 1 list',
1215 setup => ';',
1216 code => 'for (1) {}',
1217 },
1218 'loop::for::my_list4' => {
1219 desc => 'empty for loop with my var and 4 integer list',
1220 setup => '',
1221 code => 'for my $x (1,2,3,4) {}',
1222 },
1223 'loop::for::lex_list4' => {
1224 desc => 'empty for loop with lexical var and 4 integer list',
1225 setup => 'my $x;',
1226 code => 'for $x (1,2,3,4) {}',
1227 },
1228 'loop::for::pkg_list4' => {
1229 desc => 'empty for loop with package var and 4 integer list',
1230 setup => '$x = 1;',
1231 code => 'for $x (1,2,3,4) {}',
1232 },
1233 'loop::for::defsv_list4' => {
1234 desc => 'empty for loop with $_ and integer 4 list',
1235 setup => '',
1236 code => 'for (1,2,3,4) {}',
1237 },
1238
0724084c
DM
1239 'loop::for::my_array1' => {
1240 desc => 'empty for loop with my var and 1 integer array',
1241 setup => 'my @a = (1);',
1242 code => 'for my $x (@a) {}',
1243 },
1244 'loop::for::lex_array1' => {
1245 desc => 'empty for loop with lexical var and 1 integer array',
1246 setup => 'my $x; my @a = (1);',
1247 code => 'for $x (@a) {}',
1248 },
1249 'loop::for::pkg_array1' => {
1250 desc => 'empty for loop with package var and 1 integer array',
1251 setup => '$x = 1; my @a = (1);',
1252 code => 'for $x (@a) {}',
1253 },
1254 'loop::for::defsv_array1' => {
1255 desc => 'empty for loop with $_ and integer 1 array',
1256 setup => 'my @a = (@a);',
1257 code => 'for (1) {}',
1258 },
1259 'loop::for::my_array4' => {
1260 desc => 'empty for loop with my var and 4 integer array',
1261 setup => 'my @a = (1..4);',
1262 code => 'for my $x (@a) {}',
1263 },
1264 'loop::for::lex_array4' => {
1265 desc => 'empty for loop with lexical var and 4 integer array',
1266 setup => 'my $x; my @a = (1..4);',
1267 code => 'for $x (@a) {}',
1268 },
1269 'loop::for::pkg_array4' => {
1270 desc => 'empty for loop with package var and 4 integer array',
1271 setup => '$x = 1; my @a = (1..4);',
1272 code => 'for $x (@a) {}',
1273 },
1274 'loop::for::defsv_array4' => {
1275 desc => 'empty for loop with $_ and integer 4 array',
1276 setup => 'my @a = (1..4);',
1277 code => 'for (@a) {}',
1278 },
1279
cd97dc8d
DM
1280 'loop::for::next4' => {
1281 desc => 'for loop containing only next with my var and integer 4 array',
1282 setup => 'my @a = (1..4);',
1283 code => 'for my $x (@a) {next}',
1284 },
1285
56e049ca
DM
1286 'loop::grep::expr_3int' => {
1287 desc => 'grep $_ > 0, 1,2,3',
1288 setup => 'my @a',
1289 code => '@a = grep $_ > 0, 1,2,3',
1290 },
1291
1292 'loop::grep::block_3int' => {
1293 desc => 'grep { 1; $_ > 0} 1,2,3',
1294 setup => 'my @a',
1295 code => '@a = grep { 1; $_ > 0} 1,2,3',
1296 },
1297
1298 'loop::map::expr_3int' => {
1299 desc => 'map $_+1, 1,2,3',
1300 setup => 'my @a',
1301 code => '@a = map $_+1, 1,2,3',
1302 },
1303
1304 'loop::map::block_3int' => {
1305 desc => 'map { 1; $_+1} 1,2,3',
1306 setup => 'my @a',
1307 code => '@a = map { 1; $_+1} 1,2,3',
1308 },
1309
aedeb7c2
DM
1310 'loop::while::i1' => {
1311 desc => 'empty while loop 1 iteration',
1312 setup => 'my $i = 0;',
1313 code => 'while (++$i % 2) {}',
1314 },
1315 'loop::while::i4' => {
1316 desc => 'empty while loop 4 iterations',
1317 setup => 'my $i = 0;',
1318 code => 'while (++$i % 4) {}',
4c2c3128 1319 },
86f79109
YO
1320 (
1321 map {
1322 sprintf('hash::set1k::len_%04d',$_) => {
1323 desc => 'hash keys length '. $_,
1324 setup => 'my $i = "A" x ' . $_ . '; my @s= map { $i++ } 1..1000;',
1325 code => 'my %h; @h{@s}=();',
1326 },
1327 } (
1328 1..24,
1329 50,
1330 100,
1331 1000,
1332 )
1333 ),
fedf30e1 1334];