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