This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
move SET_SVANY_FOR_BODYLESS_IV() from sv.c to sv.h
[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]
36# loop:: structural code like for, while(), etc
37# regex:: regular expressions
38# string:: string handling
24fb648d 39#
9e7973fa
DM
40#
41# Each hash has three fields:
24fb648d
DM
42#
43# desc is a description of the test
44# setup is a string containing setup code
45# code is a string containing the code to run in a loop
46#
47# So typically a benchmark tool might do something like
48#
49# eval "package $token; $setup; for (1..1000000) { $code }"
9e7973fa
DM
50#
51# Currently the only tool that uses this file is Porting/bench.pl;
52# try C<perl Porting/bench.pl --help> for more info
24fb648d
DM
53
54
9e7973fa 55[
e800e134
DM
56 'call::sub::empty' => {
57 desc => 'function call with no args or body',
58 setup => 'sub f { }',
59 code => 'f()',
60 },
61 'call::sub::args3' => {
9e7973fa 62 desc => 'function call with 3 local lexical vars',
e800e134
DM
63 setup => 'sub f { my ($a, $b, $c) = @_; 1 }',
64 code => 'f(1,2,3)',
65 },
66 'call::sub::args3_ret3' => {
67 desc => 'function call with 3 local lex vars and 3 return values',
68 setup => 'my @a; sub f { my ($a, $b, $c) = @_; $a+$b, $c, 1 }',
69 code => '@a = f(1,2,3)',
70 },
71
72 'call::goto::empty' => {
73 desc => 'goto &funtion with no args or body',
74 setup => 'sub f { goto &g } sub g {}',
75 code => 'f()',
76 },
77 'call::goto::args3' => {
78 desc => 'goto &funtion with 3 local lexical vars',
79 setup => 'sub f { goto &g } sub g { my ($a, $b, $c) = @_ }',
9e7973fa
DM
80 code => 'f(1,2,3)',
81 },
82
fedf30e1
DM
83
84 'expr::array::lex_1const_0' => {
85 desc => 'lexical $array[0]',
86 setup => 'my @a = (1)',
87 code => '$a[0]',
88 },
89 'expr::array::lex_1const_m1' => {
90 desc => 'lexical $array[-1]',
91 setup => 'my @a = (1)',
92 code => '$a[-1]',
93 },
94 'expr::array::lex_2const' => {
95 desc => 'lexical $array[const][const]',
96 setup => 'my @a = ([1,2])',
97 code => '$a[0][1]',
98 },
99 'expr::array::lex_2var' => {
100 desc => 'lexical $array[$i1][$i2]',
101 setup => 'my ($i1,$i2) = (0,1); my @a = ([1,2])',
102 code => '$a[$i1][$i2]',
103 },
104 'expr::array::ref_lex_2var' => {
105 desc => 'lexical $arrayref->[$i1][$i2]',
106 setup => 'my ($i1,$i2) = (0,1); my $r = [[1,2]]',
107 code => '$r->[$i1][$i2]',
108 },
109 'expr::array::ref_lex_3const' => {
110 desc => 'lexical $arrayref->[const][const][const]',
111 setup => 'my $r = [[[1,2]]]',
112 code => '$r->[0][0][0]',
113 },
114 'expr::array::ref_expr_lex_3const' => {
115 desc => '(lexical expr)->[const][const][const]',
116 setup => 'my $r = [[[1,2]]]',
92792a1c 117 code => '($r||0)->[0][0][0]',
fedf30e1
DM
118 },
119
120
121 'expr::array::pkg_1const_0' => {
122 desc => 'package $array[0]',
92792a1c 123 setup => '@a = (1)',
fedf30e1
DM
124 code => '$a[0]',
125 },
126 'expr::array::pkg_1const_m1' => {
127 desc => 'package $array[-1]',
92792a1c 128 setup => '@a = (1)',
fedf30e1
DM
129 code => '$a[-1]',
130 },
131 'expr::array::pkg_2const' => {
132 desc => 'package $array[const][const]',
92792a1c 133 setup => '@a = ([1,2])',
fedf30e1
DM
134 code => '$a[0][1]',
135 },
136 'expr::array::pkg_2var' => {
137 desc => 'package $array[$i1][$i2]',
92792a1c 138 setup => '($i1,$i2) = (0,1); @a = ([1,2])',
fedf30e1
DM
139 code => '$a[$i1][$i2]',
140 },
141 'expr::array::ref_pkg_2var' => {
142 desc => 'package $arrayref->[$i1][$i2]',
92792a1c 143 setup => '($i1,$i2) = (0,1); $r = [[1,2]]',
fedf30e1
DM
144 code => '$r->[$i1][$i2]',
145 },
146 'expr::array::ref_pkg_3const' => {
147 desc => 'package $arrayref->[const][const][const]',
92792a1c 148 setup => '$r = [[[1,2]]]',
fedf30e1
DM
149 code => '$r->[0][0][0]',
150 },
151 'expr::array::ref_expr_pkg_3const' => {
152 desc => '(package expr)->[const][const][const]',
92792a1c
DM
153 setup => '$r = [[[1,2]]]',
154 code => '($r||0)->[0][0][0]',
fedf30e1
DM
155 },
156
157
158 'expr::arrayhash::lex_3var' => {
159 desc => 'lexical $h{$k1}[$i]{$k2}',
160 setup => 'my ($i, $k1, $k2) = (0,"foo","bar");'
161 . 'my %h = (foo => [ { bar => 1 } ])',
162 code => '$h{$k1}[$i]{$k2}',
163 },
164 'expr::arrayhash::pkg_3var' => {
165 desc => 'package $h{$k1}[$i]{$k2}',
92792a1c
DM
166 setup => '($i, $k1, $k2) = (0,"foo","bar");'
167 . '%h = (foo => [ { bar => 1 } ])',
fedf30e1
DM
168 code => '$h{$k1}[$i]{$k2}',
169 },
170
171
478d54a9 172 'expr::assign::scalar_lex_int' => {
9e7973fa
DM
173 desc => 'lexical $x = 1',
174 setup => 'my $x',
175 code => '$x = 1',
176 },
478d54a9
DM
177 'expr::assign::scalar_lex_str' => {
178 desc => 'lexical $x = "abc"',
179 setup => 'my $x',
180 code => '$x = "abc"',
181 },
182 'expr::assign::scalar_lex_strint' => {
183 desc => 'lexical $x = 1 where $x was previously a string',
184 setup => 'my $x = "abc"',
185 code => '$x = 1',
186 },
187 'expr::assign::scalar_lex_intstr' => {
188 desc => 'lexical $x = "abc" where $x was previously an int',
189 setup => 'my $x = 1;',
190 code => '$x = "abc"',
191 },
9e7973fa
DM
192 'expr::assign::2list_lex' => {
193 desc => 'lexical ($x, $y) = (1, 2)',
194 setup => 'my ($x, $y)',
195 code => '($x, $y) = (1, 2)',
24fb648d 196 },
15c41403 197
fedf30e1
DM
198
199 'expr::hash::lex_1const' => {
200 desc => 'lexical $hash{const}',
201 setup => 'my %h = ("foo" => 1)',
202 code => '$h{foo}',
203 },
204 'expr::hash::lex_2const' => {
205 desc => 'lexical $hash{const}{const}',
206 setup => 'my %h = (foo => { bar => 1 })',
207 code => '$h{foo}{bar}',
208 },
209 'expr::hash::lex_2var' => {
210 desc => 'lexical $hash{$k1}{$k2}',
211 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 })',
212 code => '$h{$k1}{$k2}',
213 },
214 'expr::hash::ref_lex_2var' => {
215 desc => 'lexical $hashref->{$k1}{$k2}',
216 setup => 'my ($k1,$k2) = qw(foo bar); my $r = {$k1 => { $k2 => 1 }}',
217 code => '$r->{$k1}{$k2}',
218 },
219 'expr::hash::ref_lex_3const' => {
220 desc => 'lexical $hashref->{const}{const}{const}',
221 setup => 'my $r = {foo => { bar => { baz => 1 }}}',
222 code => '$r->{foo}{bar}{baz}',
223 },
224 'expr::hash::ref_expr_lex_3const' => {
225 desc => '(lexical expr)->{const}{const}{const}',
226 setup => 'my $r = {foo => { bar => { baz => 1 }}}',
92792a1c 227 code => '($r||0)->{foo}{bar}{baz}',
fedf30e1
DM
228 },
229
230
231 'expr::hash::pkg_1const' => {
232 desc => 'package $hash{const}',
92792a1c 233 setup => '%h = ("foo" => 1)',
fedf30e1
DM
234 code => '$h{foo}',
235 },
236 'expr::hash::pkg_2const' => {
237 desc => 'package $hash{const}{const}',
92792a1c 238 setup => '%h = (foo => { bar => 1 })',
fedf30e1
DM
239 code => '$h{foo}{bar}',
240 },
241 'expr::hash::pkg_2var' => {
242 desc => 'package $hash{$k1}{$k2}',
92792a1c 243 setup => '($k1,$k2) = qw(foo bar); %h = ($k1 => { $k2 => 1 })',
fedf30e1
DM
244 code => '$h{$k1}{$k2}',
245 },
246 'expr::hash::ref_pkg_2var' => {
247 desc => 'package $hashref->{$k1}{$k2}',
92792a1c 248 setup => '($k1,$k2) = qw(foo bar); $r = {$k1 => { $k2 => 1 }}',
fedf30e1
DM
249 code => '$r->{$k1}{$k2}',
250 },
251 'expr::hash::ref_pkg_3const' => {
252 desc => 'package $hashref->{const}{const}{const}',
92792a1c 253 setup => '$r = {foo => { bar => { baz => 1 }}}',
fedf30e1
DM
254 code => '$r->{foo}{bar}{baz}',
255 },
256 'expr::hash::ref_expr_pkg_3const' => {
257 desc => '(package expr)->{const}{const}{const}',
92792a1c
DM
258 setup => '$r = {foo => { bar => { baz => 1 }}}',
259 code => '($r||0)->{foo}{bar}{baz}',
fedf30e1
DM
260 },
261
262
263 'expr::hash::exists_lex_2var' => {
264 desc => 'lexical exists $hash{$k1}{$k2}',
265 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 });',
266 code => 'exists $h{$k1}{$k2}',
267 },
268 'expr::hash::delete_lex_2var' => {
269 desc => 'lexical delete $hash{$k1}{$k2}',
270 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 });',
271 code => 'delete $h{$k1}{$k2}',
272 },
273
274
147f21b5
DM
275 # using a const string as second arg to index triggers using FBM.
276 # the FBM matcher special-cases 1,2-byte strings.
277 #
278 'expr::index::short_const1' => {
279 desc => 'index of a short string against a 1 char const substr',
280 setup => 'my $x = "aaaab"',
281 code => 'index $x, "b"',
282 },
283 'expr::index::long_const1' => {
284 desc => 'index of a long string against a 1 char const substr',
285 setup => 'my $x = "a" x 1000 . "b"',
286 code => 'index $x, "b"',
287 },
288 'expr::index::short_const2aabc_bc' => {
289 desc => 'index of a short string against a 2 char const substr',
290 setup => 'my $x = "aaaabc"',
291 code => 'index $x, "bc"',
292 },
293 'expr::index::long_const2aabc_bc' => {
294 desc => 'index of a long string against a 2 char const substr',
295 setup => 'my $x = "a" x 1000 . "bc"',
296 code => 'index $x, "bc"',
297 },
298 'expr::index::long_const2aa_ab' => {
299 desc => 'index of a long string aaa.. against const substr "ab"',
300 setup => 'my $x = "a" x 1000',
301 code => 'index $x, "ab"',
302 },
303 'expr::index::long_const2bb_ab' => {
304 desc => 'index of a long string bbb.. against const substr "ab"',
305 setup => 'my $x = "b" x 1000',
306 code => 'index $x, "ab"',
307 },
308 'expr::index::long_const2aa_bb' => {
309 desc => 'index of a long string aaa.. against const substr "bb"',
310 setup => 'my $x = "a" x 1000',
311 code => 'index $x, "bb"',
312 },
313 # this one is designed to be pathological
314 'expr::index::long_const2ab_aa' => {
315 desc => 'index of a long string abab.. against const substr "aa"',
316 setup => 'my $x = "ab" x 500',
317 code => 'index $x, "aa"',
318 },
319 # near misses with gaps, 1st letter
320 'expr::index::long_const2aaxx_xy' => {
321 desc => 'index of a long string with "xx"s against const substr "xy"',
322 setup => 'my $x = "aaaaaaaaxx" x 100',
323 code => 'index $x, "xy"',
324 },
325 # near misses with gaps, 2nd letter
326 'expr::index::long_const2aayy_xy' => {
327 desc => 'index of a long string with "yy"s against const substr "xy"',
328 setup => 'my $x = "aaaaaaaayy" x 100',
329 code => 'index $x, "xy"',
330 },
331 # near misses with gaps, duplicate letter
332 'expr::index::long_const2aaxy_xx' => {
333 desc => 'index of a long string with "xy"s against const substr "xx"',
334 setup => 'my $x = "aaaaaaaaxy" x 100',
335 code => 'index $x, "xx"',
336 },
337 # alternating near misses with gaps
338 'expr::index::long_const2aaxxaayy_xy' => {
339 desc => 'index of a long string with "xx/yy"s against const substr "xy"',
340 setup => 'my $x = "aaaaaaaaxxbbbbbbbbyy" x 50',
341 code => 'index $x, "xy"',
342 },
343 'expr::index::short_const3aabcd_bcd' => {
344 desc => 'index of a short string against a 3 char const substr',
345 setup => 'my $x = "aaaabcd"',
346 code => 'index $x, "bcd"',
347 },
348 'expr::index::long_const3aabcd_bcd' => {
349 desc => 'index of a long string against a 3 char const substr',
350 setup => 'my $x = "a" x 1000 . "bcd"',
351 code => 'index $x, "bcd"',
352 },
353 'expr::index::long_const3ab_abc' => {
354 desc => 'index of a long string of "ab"s against a 3 char const substr "abc"',
355 setup => 'my $x = "ab" x 500',
356 code => 'index $x, "abc"',
357 },
358 'expr::index::long_const3bc_abc' => {
359 desc => 'index of a long string of "bc"s against a 3 char const substr "abc"',
360 setup => 'my $x = "bc" x 500',
361 code => 'index $x, "abc"',
362 },
41f678d9 363 'expr::index::utf8_position_1' => {
15c41403 364 desc => 'index of a utf8 string, matching at position 1',
92792a1c 365 setup => 'my $x = "abc". chr(0x100); chop $x',
15c41403
JR
366 code => 'index $x, "b"',
367 },
24fb648d 368
a5f48505
DM
369
370 # list assign, OP_AASSIGN
371
372
373 # (....) = ()
374
375 'expr::aassign::ma_empty' => {
376 desc => 'my array assigned empty',
377 setup => '',
378 code => 'my @a = ()',
379 },
380 'expr::aassign::lax_empty' => {
381 desc => 'non-empty lexical array assigned empty',
382 setup => 'my @a = 1..3;',
383 code => '@a = ()',
384 },
385 'expr::aassign::llax_empty' => {
386 desc => 'non-empty lexical var and array assigned empty',
387 setup => 'my ($x, @a) = 1..4;',
388 code => '($x, @a) = ()',
389 },
390 'expr::aassign::3m_empty' => {
391 desc => 'three my vars assigned empty',
392 setup => '',
393 code => 'my ($x,$y,$z) = ()',
394 },
395 'expr::aassign::3l_empty' => {
396 desc => 'three lexical vars assigned empty',
397 setup => 'my ($x,$y,$z)',
398 code => '($x,$y,$z) = ()',
399 },
400 'expr::aassign::pa_empty' => {
401 desc => 'package array assigned empty',
402 setup => '',
403 code => '@a = ()',
404 },
405 'expr::aassign::pax_empty' => {
406 desc => 'non-empty package array assigned empty',
407 setup => '@a = (1,2,3)',
408 code => '@a = ()',
409 },
410 'expr::aassign::3p_empty' => {
411 desc => 'three package vars assigned empty',
412 setup => '($x,$y,$z) = 1..3;',
413 code => '($x,$y,$z) = ()',
414 },
415
416 # (....) = (1,2,3)
417
418 'expr::aassign::ma_3c' => {
419 desc => 'my array assigned 3 consts',
420 setup => '',
421 code => 'my @a = (1,2,3)',
422 },
423 'expr::aassign::lax_3c' => {
424 desc => 'non-empty lexical array assigned 3 consts',
425 setup => 'my @a = 1..3;',
426 code => '@a = (1,2,3)',
427 },
428 'expr::aassign::llax_3c' => {
429 desc => 'non-empty lexical var and array assigned 3 consts',
430 setup => 'my ($x, @a) = 1..4;',
431 code => '($x, @a) = (1,2,3)',
432 },
433 'expr::aassign::3m_3c' => {
434 desc => 'three my vars assigned 3 consts',
435 setup => '',
436 code => 'my ($x,$y,$z) = (1,2,3)',
437 },
438 'expr::aassign::3l_3c' => {
439 desc => 'three lexical vars assigned 3 consts',
440 setup => 'my ($x,$y,$z)',
441 code => '($x,$y,$z) = (1,2,3)',
442 },
443 'expr::aassign::pa_3c' => {
444 desc => 'package array assigned 3 consts',
445 setup => '',
446 code => '@a = (1,2,3)',
447 },
448 'expr::aassign::pax_3c' => {
449 desc => 'non-empty package array assigned 3 consts',
450 setup => '@a = (1,2,3)',
451 code => '@a = (1,2,3)',
452 },
453 'expr::aassign::3p_3c' => {
454 desc => 'three package vars assigned 3 consts',
455 setup => '($x,$y,$z) = 1..3;',
456 code => '($x,$y,$z) = (1,2,3)',
457 },
458
459 # (....) = @lexical
460
461 'expr::aassign::ma_la' => {
462 desc => 'my array assigned lexical array',
463 setup => 'my @init = 1..3;',
464 code => 'my @a = @init',
465 },
466 'expr::aassign::lax_la' => {
467 desc => 'non-empty lexical array assigned lexical array',
468 setup => 'my @init = 1..3; my @a = 1..3;',
469 code => '@a = @init',
470 },
471 'expr::aassign::llax_la' => {
472 desc => 'non-empty lexical var and array assigned lexical array',
473 setup => 'my @init = 1..3; my ($x, @a) = 1..4;',
474 code => '($x, @a) = @init',
475 },
476 'expr::aassign::3m_la' => {
477 desc => 'three my vars assigned lexical array',
478 setup => 'my @init = 1..3;',
479 code => 'my ($x,$y,$z) = @init',
480 },
481 'expr::aassign::3l_la' => {
482 desc => 'three lexical vars assigned lexical array',
483 setup => 'my @init = 1..3; my ($x,$y,$z)',
484 code => '($x,$y,$z) = @init',
485 },
486 'expr::aassign::pa_la' => {
487 desc => 'package array assigned lexical array',
488 setup => 'my @init = 1..3;',
489 code => '@a = @init',
490 },
491 'expr::aassign::pax_la' => {
492 desc => 'non-empty package array assigned lexical array',
493 setup => 'my @init = 1..3; @a = @init',
494 code => '@a = @init',
495 },
496 'expr::aassign::3p_la' => {
497 desc => 'three package vars assigned lexical array',
498 setup => 'my @init = 1..3; ($x,$y,$z) = 1..3;',
499 code => '($x,$y,$z) = @init',
500 },
501
502 # (....) = @package
503
504 'expr::aassign::ma_pa' => {
505 desc => 'my array assigned package array',
506 setup => '@init = 1..3;',
507 code => 'my @a = @init',
508 },
509 'expr::aassign::lax_pa' => {
510 desc => 'non-empty lexical array assigned package array',
511 setup => '@init = 1..3; my @a = 1..3;',
512 code => '@a = @init',
513 },
514 'expr::aassign::llax_pa' => {
515 desc => 'non-empty lexical var and array assigned package array',
516 setup => '@init = 1..3; my ($x, @a) = 1..4;',
517 code => '($x, @a) = @init',
518 },
519 'expr::aassign::3m_pa' => {
520 desc => 'three my vars assigned package array',
521 setup => '@init = 1..3;',
522 code => 'my ($x,$y,$z) = @init',
523 },
524 'expr::aassign::3l_pa' => {
525 desc => 'three lexical vars assigned package array',
526 setup => '@init = 1..3; my ($x,$y,$z)',
527 code => '($x,$y,$z) = @init',
528 },
529 'expr::aassign::pa_pa' => {
530 desc => 'package array assigned package array',
531 setup => '@init = 1..3;',
532 code => '@a = @init',
533 },
534 'expr::aassign::pax_pa' => {
535 desc => 'non-empty package array assigned package array',
536 setup => '@init = 1..3; @a = @init',
537 code => '@a = @init',
538 },
539 'expr::aassign::3p_pa' => {
540 desc => 'three package vars assigned package array',
541 setup => '@init = 1..3; ($x,$y,$z) = 1..3;',
542 code => '($x,$y,$z) = @init',
543 },
544
545 # (....) = @_;
546
547 'expr::aassign::ma_defary' => {
548 desc => 'my array assigned @_',
549 setup => '@_ = 1..3;',
550 code => 'my @a = @_',
551 },
552 'expr::aassign::lax_defary' => {
553 desc => 'non-empty lexical array assigned @_',
554 setup => '@_ = 1..3; my @a = 1..3;',
555 code => '@a = @_',
556 },
557 'expr::aassign::llax_defary' => {
558 desc => 'non-empty lexical var and array assigned @_',
559 setup => '@_ = 1..3; my ($x, @a) = 1..4;',
560 code => '($x, @a) = @_',
561 },
562 'expr::aassign::3m_defary' => {
563 desc => 'three my vars assigned @_',
564 setup => '@_ = 1..3;',
565 code => 'my ($x,$y,$z) = @_',
566 },
567 'expr::aassign::3l_defary' => {
568 desc => 'three lexical vars assigned @_',
569 setup => '@_ = 1..3; my ($x,$y,$z)',
570 code => '($x,$y,$z) = @_',
571 },
572 'expr::aassign::pa_defary' => {
573 desc => 'package array assigned @_',
574 setup => '@_ = 1..3;',
575 code => '@a = @_',
576 },
577 'expr::aassign::pax_defary' => {
578 desc => 'non-empty package array assigned @_',
579 setup => '@_ = 1..3; @a = @_',
580 code => '@a = @_',
581 },
582 'expr::aassign::3p_defary' => {
583 desc => 'three package vars assigned @_',
584 setup => '@_ = 1..3; ($x,$y,$z) = 1..3;',
585 code => '($x,$y,$z) = @_',
586 },
587
588
589 # (....) = ($lex1,$lex2,$lex3);
590
591 'expr::aassign::ma_3l' => {
592 desc => 'my array assigned lexicals',
593 setup => 'my ($v1,$v2,$v3) = 1..3;',
594 code => 'my @a = ($v1,$v2,$v3)',
595 },
596 'expr::aassign::lax_3l' => {
597 desc => 'non-empty lexical array assigned lexicals',
598 setup => 'my ($v1,$v2,$v3) = 1..3; my @a = 1..3;',
599 code => '@a = ($v1,$v2,$v3)',
600 },
601 'expr::aassign::llax_3l' => {
602 desc => 'non-empty lexical var and array assigned lexicals',
603 setup => 'my ($v1,$v2,$v3) = 1..3; my ($x, @a) = 1..4;',
604 code => '($x, @a) = ($v1,$v2,$v3)',
605 },
606 'expr::aassign::3m_3l' => {
607 desc => 'three my vars assigned lexicals',
608 setup => 'my ($v1,$v2,$v3) = 1..3;',
609 code => 'my ($x,$y,$z) = ($v1,$v2,$v3)',
610 },
611 'expr::aassign::3l_3l' => {
612 desc => 'three lexical vars assigned lexicals',
613 setup => 'my ($v1,$v2,$v3) = 1..3; my ($x,$y,$z)',
614 code => '($x,$y,$z) = ($v1,$v2,$v3)',
615 },
616 'expr::aassign::pa_3l' => {
617 desc => 'package array assigned lexicals',
618 setup => 'my ($v1,$v2,$v3) = 1..3;',
619 code => '@a = ($v1,$v2,$v3)',
620 },
621 'expr::aassign::pax_3l' => {
622 desc => 'non-empty package array assigned lexicals',
623 setup => 'my ($v1,$v2,$v3) = 1..3; @a = @_',
624 code => '@a = ($v1,$v2,$v3)',
625 },
626 'expr::aassign::3p_3l' => {
627 desc => 'three package vars assigned lexicals',
628 setup => 'my ($v1,$v2,$v3) = 1..3; ($x,$y,$z) = 1..3;',
629 code => '($x,$y,$z) = ($v1,$v2,$v3)',
630 },
631
632
633 # (....) = ($pkg1,$pkg2,$pkg3);
634
635 'expr::aassign::ma_3p' => {
636 desc => 'my array assigned 3 package vars',
637 setup => '($v1,$v2,$v3) = 1..3;',
638 code => 'my @a = ($v1,$v2,$v3)',
639 },
640 'expr::aassign::lax_3p' => {
641 desc => 'non-empty lexical array assigned 3 package vars',
642 setup => '($v1,$v2,$v3) = 1..3; my @a = 1..3;',
643 code => '@a = ($v1,$v2,$v3)',
644 },
645 'expr::aassign::llax_3p' => {
646 desc => 'non-empty lexical var and array assigned 3 package vars',
647 setup => '($v1,$v2,$v3) = 1..3; my ($x, @a) = 1..4;',
648 code => '($x, @a) = ($v1,$v2,$v3)',
649 },
650 'expr::aassign::3m_3p' => {
651 desc => 'three my vars assigned 3 package vars',
652 setup => '($v1,$v2,$v3) = 1..3;',
653 code => 'my ($x,$y,$z) = ($v1,$v2,$v3)',
654 },
655 'expr::aassign::3l_3p' => {
656 desc => 'three lexical vars assigned 3 package vars',
657 setup => '($v1,$v2,$v3) = 1..3; my ($x,$y,$z)',
658 code => '($x,$y,$z) = ($v1,$v2,$v3)',
659 },
660 'expr::aassign::pa_3p' => {
661 desc => 'package array assigned 3 package vars',
662 setup => '($v1,$v2,$v3) = 1..3;',
663 code => '@a = ($v1,$v2,$v3)',
664 },
665 'expr::aassign::pax_3p' => {
666 desc => 'non-empty package array assigned 3 package vars',
667 setup => '($v1,$v2,$v3) = 1..3; @a = @_',
668 code => '@a = ($v1,$v2,$v3)',
669 },
670 'expr::aassign::3p_3p' => {
671 desc => 'three package vars assigned 3 package vars',
672 setup => '($v1,$v2,$v3) = 1..3; ($x,$y,$z) = 1..3;',
673 code => '($x,$y,$z) = ($v1,$v2,$v3)',
674 },
675
676
677 # (....) = (1,2,$shared);
678
679 'expr::aassign::llax_2c1s' => {
680 desc => 'non-empty lexical var and array assigned 2 consts and 1 shared var',
681 setup => 'my ($x, @a) = 1..4;',
682 code => '($x, @a) = (1,2,$x)',
683 },
684 'expr::aassign::3l_2c1s' => {
685 desc => 'three lexical vars assigned 2 consts and 1 shared var',
686 setup => 'my ($x,$y,$z) = 1..3;',
687 code => '($x,$y,$z) = (1,2,$x)',
688 },
689 'expr::aassign::3p_2c1s' => {
690 desc => 'three package vars assigned 2 consts and 1 shared var',
691 setup => '($x,$y,$z) = 1..3;',
692 code => '($x,$y,$z) = (1,2,$x)',
693 },
694
695
696 # ($a,$b) = ($b,$a);
697
698 'expr::aassign::2l_swap' => {
699 desc => 'swap two lexical vars',
700 setup => 'my ($a,$b) = (1,2)',
701 code => '($a,$b) = ($b,$a)',
702 },
703 'expr::aassign::2p_swap' => {
704 desc => 'swap two package vars',
705 setup => '($a,$b) = (1,2)',
706 code => '($a,$b) = ($b,$a)',
707 },
708 'expr::aassign::2laelem_swap' => {
709 desc => 'swap two lexical vars',
710 setup => 'my @a = (1,2)',
711 code => '($a[0],$a[1]) = ($a[1],$a[0])',
712 },
713
714 # misc list assign
715
716 'expr::aassign::5l_4l1s' => {
717 desc => 'long list of lexical vars, 1 shared',
718 setup => 'my ($a,$b,$c,$d,$e) = 1..5',
719 code => '($a,$b,$c,$d,$e) = ($a,$a,$c,$d,$e)',
720 },
721
722 'expr::aassign::5p_4p1s' => {
723 desc => 'long list of package vars, 1 shared',
724 setup => '($a,$b,$c,$d,$e) = 1..5',
725 code => '($a,$b,$c,$d,$e) = ($a,$a,$c,$d,$e)',
726 },
727 'expr::aassign::5l_defary' => {
728 desc => 'long list of lexical vars to assign @_ to',
729 setup => '@_ = 1..5',
730 code => 'my ($a,$b,$c,$d,$e) = @_',
731 },
732 'expr::aassign::5l1la_defary' => {
733 desc => 'long list of lexical vars plus long slurp to assign @_ to',
734 setup => '@_ = 1..20',
735 code => 'my ($a,$b,$c,$d,$e,@rest) = @_',
736 },
808ce557
DM
737 'expr::aassign::1l_2l' => {
738 desc => 'single lexical LHS',
739 setup => 'my $x = 1;',
740 code => '(undef,$x) = ($x,$x)',
741 },
742 'expr::aassign::2l_1l' => {
743 desc => 'single lexical RHS',
744 setup => 'my $x = 1;',
9ae0115f
DM
745 code => '($x,$x) = ($x)',
746 },
747 'expr::aassign::2l_1ul' => {
748 desc => 'undef and single lexical RHS',
749 setup => 'my $x = 1;',
808ce557
DM
750 code => '($x,$x) = (undef, $x)',
751 },
a5f48505
DM
752
753
230ee21f
DM
754 'expr::arith::add_lex_ii' => {
755 desc => 'add two integers and assign to a lexical var',
756 setup => 'my ($x,$y,$z) = 1..3;',
757 code => '$z = $x + $y',
758 },
759 'expr::arith::add_pkg_ii' => {
760 desc => 'add two integers and assign to a package var',
761 setup => 'my ($x,$y) = 1..2; $z = 3;',
762 code => '$z = $x + $y',
763 },
764 'expr::arith::add_lex_nn' => {
765 desc => 'add two NVs and assign to a lexical var',
766 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
767 code => '$z = $x + $y',
768 },
769 'expr::arith::add_pkg_nn' => {
770 desc => 'add two NVs and assign to a package var',
771 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
772 code => '$z = $x + $y',
773 },
774 'expr::arith::add_lex_ni' => {
775 desc => 'add an int and an NV and assign to a lexical var',
776 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
777 code => '$z = $x + $y',
778 },
779 'expr::arith::add_pkg_ni' => {
780 desc => 'add an int and an NV and assign to a package var',
781 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
782 code => '$z = $x + $y',
783 },
784
785 'expr::arith::sub_lex_ii' => {
786 desc => 'subtract two integers and assign to a lexical var',
787 setup => 'my ($x,$y,$z) = 1..3;',
788 code => '$z = $x - $y',
789 },
790 'expr::arith::sub_pkg_ii' => {
791 desc => 'subtract two integers and assign to a package var',
792 setup => 'my ($x,$y) = 1..2; $z = 3;',
793 code => '$z = $x - $y',
794 },
795 'expr::arith::sub_lex_nn' => {
796 desc => 'subtract two NVs and assign to a lexical var',
797 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
798 code => '$z = $x - $y',
799 },
800 'expr::arith::sub_pkg_nn' => {
801 desc => 'subtract two NVs and assign to a package var',
802 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
803 code => '$z = $x - $y',
804 },
805 'expr::arith::sub_lex_ni' => {
806 desc => 'subtract an int and an NV and assign to a lexical var',
807 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
808 code => '$z = $x - $y',
809 },
810 'expr::arith::sub_pkg_ni' => {
811 desc => 'subtract an int and an NV and assign to a package var',
812 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
813 code => '$z = $x - $y',
814 },
815
816 'expr::arith::mult_lex_ii' => {
817 desc => 'multiply two integers and assign to a lexical var',
818 setup => 'my ($x,$y,$z) = 1..3;',
819 code => '$z = $x * $y',
820 },
821 'expr::arith::mult_pkg_ii' => {
822 desc => 'multiply two integers and assign to a package var',
823 setup => 'my ($x,$y) = 1..2; $z = 3;',
824 code => '$z = $x * $y',
825 },
826 'expr::arith::mult_lex_nn' => {
827 desc => 'multiply two NVs and assign to a lexical var',
828 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
829 code => '$z = $x * $y',
830 },
831 'expr::arith::mult_pkg_nn' => {
832 desc => 'multiply two NVs and assign to a package var',
833 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
834 code => '$z = $x * $y',
835 },
836 'expr::arith::mult_lex_ni' => {
837 desc => 'multiply an int and an NV and assign to a lexical var',
838 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
839 code => '$z = $x * $y',
840 },
841 'expr::arith::mult_pkg_ni' => {
842 desc => 'multiply an int and an NV and assign to a package var',
843 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
844 code => '$z = $x * $y',
845 },
846
4c2c3128
DM
847 'expr::arith::preinc' => {
848 desc => '++$x',
849 setup => 'my $x = 1;',
850 code => '++$x',
851 },
852 'expr::arith::predec' => {
853 desc => '--$x',
854 setup => 'my $x = 1;',
855 code => '--$x',
856 },
857 'expr::arith::postinc' => {
858 desc => '$x++',
859 setup => 'my $x = 1; my $y',
860 code => '$y = $x++', # scalar context so not optimised to ++$x
861 },
862 'expr::arith::postdec' => {
863 desc => '$x--',
864 setup => 'my $x = 1; my $y',
865 code => '$y = $x--', # scalar context so not optimised to --$x
b52de964
DM
866 },
867
aedeb7c2
DM
868 'loop::block' => {
869 desc => 'empty basic loop',
870 setup => ';',
871 code => '{1;}',
872 },
873
874 'loop::do' => {
875 desc => 'basic do block',
876 setup => 'my $x; my $y = 2;',
877 code => '$x = do {1; $y}', # the ';' stops the do being optimised
878 },
879
880 'loop::for::my_range1' => {
881 desc => 'empty for loop with my var and 1 integer range',
882 setup => '',
883 code => 'for my $x (1..1) {}',
884 },
885 'loop::for::lex_range1' => {
886 desc => 'empty for loop with lexical var and 1 integer range',
887 setup => 'my $x;',
888 code => 'for $x (1..1) {}',
889 },
890 'loop::for::pkg_range1' => {
891 desc => 'empty for loop with package var and 1 integer range',
892 setup => '$x = 1;',
893 code => 'for $x (1..1) {}',
894 },
895 'loop::for::defsv_range1' => {
896 desc => 'empty for loop with $_ and integer 1 range',
897 setup => ';',
898 code => 'for (1..1) {}',
899 },
900 'loop::for::my_range4' => {
901 desc => 'empty for loop with my var and 4 integer range',
902 setup => '',
903 code => 'for my $x (1..4) {}',
904 },
905 'loop::for::lex_range4' => {
906 desc => 'empty for loop with lexical var and 4 integer range',
907 setup => 'my $x;',
908 code => 'for $x (1..4) {}',
909 },
910 'loop::for::pkg_range4' => {
911 desc => 'empty for loop with package var and 4 integer range',
912 setup => '$x = 1;',
913 code => 'for $x (1..4) {}',
914 },
915 'loop::for::defsv_range4' => {
916 desc => 'empty for loop with $_ and integer 4 range',
917 setup => ';',
918 code => 'for (1..4) {}',
919 },
4c2c3128 920
aedeb7c2
DM
921 'loop::for::my_list1' => {
922 desc => 'empty for loop with my var and 1 integer list',
b52de964 923 setup => '',
aedeb7c2
DM
924 code => 'for my $x (1) {}',
925 },
926 'loop::for::lex_list1' => {
927 desc => 'empty for loop with lexical var and 1 integer list',
928 setup => 'my $x;',
929 code => 'for $x (1) {}',
930 },
931 'loop::for::pkg_list1' => {
932 desc => 'empty for loop with package var and 1 integer list',
933 setup => '$x = 1;',
934 code => 'for $x (1) {}',
935 },
936 'loop::for::defsv_list1' => {
937 desc => 'empty for loop with $_ and integer 1 list',
938 setup => ';',
939 code => 'for (1) {}',
940 },
941 'loop::for::my_list4' => {
942 desc => 'empty for loop with my var and 4 integer list',
943 setup => '',
944 code => 'for my $x (1,2,3,4) {}',
945 },
946 'loop::for::lex_list4' => {
947 desc => 'empty for loop with lexical var and 4 integer list',
948 setup => 'my $x;',
949 code => 'for $x (1,2,3,4) {}',
950 },
951 'loop::for::pkg_list4' => {
952 desc => 'empty for loop with package var and 4 integer list',
953 setup => '$x = 1;',
954 code => 'for $x (1,2,3,4) {}',
955 },
956 'loop::for::defsv_list4' => {
957 desc => 'empty for loop with $_ and integer 4 list',
958 setup => '',
959 code => 'for (1,2,3,4) {}',
960 },
961
0724084c
DM
962 'loop::for::my_array1' => {
963 desc => 'empty for loop with my var and 1 integer array',
964 setup => 'my @a = (1);',
965 code => 'for my $x (@a) {}',
966 },
967 'loop::for::lex_array1' => {
968 desc => 'empty for loop with lexical var and 1 integer array',
969 setup => 'my $x; my @a = (1);',
970 code => 'for $x (@a) {}',
971 },
972 'loop::for::pkg_array1' => {
973 desc => 'empty for loop with package var and 1 integer array',
974 setup => '$x = 1; my @a = (1);',
975 code => 'for $x (@a) {}',
976 },
977 'loop::for::defsv_array1' => {
978 desc => 'empty for loop with $_ and integer 1 array',
979 setup => 'my @a = (@a);',
980 code => 'for (1) {}',
981 },
982 'loop::for::my_array4' => {
983 desc => 'empty for loop with my var and 4 integer array',
984 setup => 'my @a = (1..4);',
985 code => 'for my $x (@a) {}',
986 },
987 'loop::for::lex_array4' => {
988 desc => 'empty for loop with lexical var and 4 integer array',
989 setup => 'my $x; my @a = (1..4);',
990 code => 'for $x (@a) {}',
991 },
992 'loop::for::pkg_array4' => {
993 desc => 'empty for loop with package var and 4 integer array',
994 setup => '$x = 1; my @a = (1..4);',
995 code => 'for $x (@a) {}',
996 },
997 'loop::for::defsv_array4' => {
998 desc => 'empty for loop with $_ and integer 4 array',
999 setup => 'my @a = (1..4);',
1000 code => 'for (@a) {}',
1001 },
1002
aedeb7c2
DM
1003 'loop::while::i1' => {
1004 desc => 'empty while loop 1 iteration',
1005 setup => 'my $i = 0;',
1006 code => 'while (++$i % 2) {}',
1007 },
1008 'loop::while::i4' => {
1009 desc => 'empty while loop 4 iterations',
1010 setup => 'my $i = 0;',
1011 code => 'while (++$i % 4) {}',
4c2c3128
DM
1012 },
1013
fedf30e1 1014];