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