This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make remaining context types avoid ENTER/LEAVE
[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
9e7973fa
DM
172 'expr::assign::scalar_lex' => {
173 desc => 'lexical $x = 1',
174 setup => 'my $x',
175 code => '$x = 1',
176 },
177 'expr::assign::2list_lex' => {
178 desc => 'lexical ($x, $y) = (1, 2)',
179 setup => 'my ($x, $y)',
180 code => '($x, $y) = (1, 2)',
24fb648d 181 },
15c41403 182
fedf30e1
DM
183
184 'expr::hash::lex_1const' => {
185 desc => 'lexical $hash{const}',
186 setup => 'my %h = ("foo" => 1)',
187 code => '$h{foo}',
188 },
189 'expr::hash::lex_2const' => {
190 desc => 'lexical $hash{const}{const}',
191 setup => 'my %h = (foo => { bar => 1 })',
192 code => '$h{foo}{bar}',
193 },
194 'expr::hash::lex_2var' => {
195 desc => 'lexical $hash{$k1}{$k2}',
196 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 })',
197 code => '$h{$k1}{$k2}',
198 },
199 'expr::hash::ref_lex_2var' => {
200 desc => 'lexical $hashref->{$k1}{$k2}',
201 setup => 'my ($k1,$k2) = qw(foo bar); my $r = {$k1 => { $k2 => 1 }}',
202 code => '$r->{$k1}{$k2}',
203 },
204 'expr::hash::ref_lex_3const' => {
205 desc => 'lexical $hashref->{const}{const}{const}',
206 setup => 'my $r = {foo => { bar => { baz => 1 }}}',
207 code => '$r->{foo}{bar}{baz}',
208 },
209 'expr::hash::ref_expr_lex_3const' => {
210 desc => '(lexical expr)->{const}{const}{const}',
211 setup => 'my $r = {foo => { bar => { baz => 1 }}}',
92792a1c 212 code => '($r||0)->{foo}{bar}{baz}',
fedf30e1
DM
213 },
214
215
216 'expr::hash::pkg_1const' => {
217 desc => 'package $hash{const}',
92792a1c 218 setup => '%h = ("foo" => 1)',
fedf30e1
DM
219 code => '$h{foo}',
220 },
221 'expr::hash::pkg_2const' => {
222 desc => 'package $hash{const}{const}',
92792a1c 223 setup => '%h = (foo => { bar => 1 })',
fedf30e1
DM
224 code => '$h{foo}{bar}',
225 },
226 'expr::hash::pkg_2var' => {
227 desc => 'package $hash{$k1}{$k2}',
92792a1c 228 setup => '($k1,$k2) = qw(foo bar); %h = ($k1 => { $k2 => 1 })',
fedf30e1
DM
229 code => '$h{$k1}{$k2}',
230 },
231 'expr::hash::ref_pkg_2var' => {
232 desc => 'package $hashref->{$k1}{$k2}',
92792a1c 233 setup => '($k1,$k2) = qw(foo bar); $r = {$k1 => { $k2 => 1 }}',
fedf30e1
DM
234 code => '$r->{$k1}{$k2}',
235 },
236 'expr::hash::ref_pkg_3const' => {
237 desc => 'package $hashref->{const}{const}{const}',
92792a1c 238 setup => '$r = {foo => { bar => { baz => 1 }}}',
fedf30e1
DM
239 code => '$r->{foo}{bar}{baz}',
240 },
241 'expr::hash::ref_expr_pkg_3const' => {
242 desc => '(package expr)->{const}{const}{const}',
92792a1c
DM
243 setup => '$r = {foo => { bar => { baz => 1 }}}',
244 code => '($r||0)->{foo}{bar}{baz}',
fedf30e1
DM
245 },
246
247
248 'expr::hash::exists_lex_2var' => {
249 desc => 'lexical exists $hash{$k1}{$k2}',
250 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 });',
251 code => 'exists $h{$k1}{$k2}',
252 },
253 'expr::hash::delete_lex_2var' => {
254 desc => 'lexical delete $hash{$k1}{$k2}',
255 setup => 'my ($k1,$k2) = qw(foo bar); my %h = ($k1 => { $k2 => 1 });',
256 code => 'delete $h{$k1}{$k2}',
257 },
258
259
147f21b5
DM
260 # using a const string as second arg to index triggers using FBM.
261 # the FBM matcher special-cases 1,2-byte strings.
262 #
263 'expr::index::short_const1' => {
264 desc => 'index of a short string against a 1 char const substr',
265 setup => 'my $x = "aaaab"',
266 code => 'index $x, "b"',
267 },
268 'expr::index::long_const1' => {
269 desc => 'index of a long string against a 1 char const substr',
270 setup => 'my $x = "a" x 1000 . "b"',
271 code => 'index $x, "b"',
272 },
273 'expr::index::short_const2aabc_bc' => {
274 desc => 'index of a short string against a 2 char const substr',
275 setup => 'my $x = "aaaabc"',
276 code => 'index $x, "bc"',
277 },
278 'expr::index::long_const2aabc_bc' => {
279 desc => 'index of a long string against a 2 char const substr',
280 setup => 'my $x = "a" x 1000 . "bc"',
281 code => 'index $x, "bc"',
282 },
283 'expr::index::long_const2aa_ab' => {
284 desc => 'index of a long string aaa.. against const substr "ab"',
285 setup => 'my $x = "a" x 1000',
286 code => 'index $x, "ab"',
287 },
288 'expr::index::long_const2bb_ab' => {
289 desc => 'index of a long string bbb.. against const substr "ab"',
290 setup => 'my $x = "b" x 1000',
291 code => 'index $x, "ab"',
292 },
293 'expr::index::long_const2aa_bb' => {
294 desc => 'index of a long string aaa.. against const substr "bb"',
295 setup => 'my $x = "a" x 1000',
296 code => 'index $x, "bb"',
297 },
298 # this one is designed to be pathological
299 'expr::index::long_const2ab_aa' => {
300 desc => 'index of a long string abab.. against const substr "aa"',
301 setup => 'my $x = "ab" x 500',
302 code => 'index $x, "aa"',
303 },
304 # near misses with gaps, 1st letter
305 'expr::index::long_const2aaxx_xy' => {
306 desc => 'index of a long string with "xx"s against const substr "xy"',
307 setup => 'my $x = "aaaaaaaaxx" x 100',
308 code => 'index $x, "xy"',
309 },
310 # near misses with gaps, 2nd letter
311 'expr::index::long_const2aayy_xy' => {
312 desc => 'index of a long string with "yy"s against const substr "xy"',
313 setup => 'my $x = "aaaaaaaayy" x 100',
314 code => 'index $x, "xy"',
315 },
316 # near misses with gaps, duplicate letter
317 'expr::index::long_const2aaxy_xx' => {
318 desc => 'index of a long string with "xy"s against const substr "xx"',
319 setup => 'my $x = "aaaaaaaaxy" x 100',
320 code => 'index $x, "xx"',
321 },
322 # alternating near misses with gaps
323 'expr::index::long_const2aaxxaayy_xy' => {
324 desc => 'index of a long string with "xx/yy"s against const substr "xy"',
325 setup => 'my $x = "aaaaaaaaxxbbbbbbbbyy" x 50',
326 code => 'index $x, "xy"',
327 },
328 'expr::index::short_const3aabcd_bcd' => {
329 desc => 'index of a short string against a 3 char const substr',
330 setup => 'my $x = "aaaabcd"',
331 code => 'index $x, "bcd"',
332 },
333 'expr::index::long_const3aabcd_bcd' => {
334 desc => 'index of a long string against a 3 char const substr',
335 setup => 'my $x = "a" x 1000 . "bcd"',
336 code => 'index $x, "bcd"',
337 },
338 'expr::index::long_const3ab_abc' => {
339 desc => 'index of a long string of "ab"s against a 3 char const substr "abc"',
340 setup => 'my $x = "ab" x 500',
341 code => 'index $x, "abc"',
342 },
343 'expr::index::long_const3bc_abc' => {
344 desc => 'index of a long string of "bc"s against a 3 char const substr "abc"',
345 setup => 'my $x = "bc" x 500',
346 code => 'index $x, "abc"',
347 },
41f678d9 348 'expr::index::utf8_position_1' => {
15c41403 349 desc => 'index of a utf8 string, matching at position 1',
92792a1c 350 setup => 'my $x = "abc". chr(0x100); chop $x',
15c41403
JR
351 code => 'index $x, "b"',
352 },
24fb648d 353
a5f48505
DM
354
355 # list assign, OP_AASSIGN
356
357
358 # (....) = ()
359
360 'expr::aassign::ma_empty' => {
361 desc => 'my array assigned empty',
362 setup => '',
363 code => 'my @a = ()',
364 },
365 'expr::aassign::lax_empty' => {
366 desc => 'non-empty lexical array assigned empty',
367 setup => 'my @a = 1..3;',
368 code => '@a = ()',
369 },
370 'expr::aassign::llax_empty' => {
371 desc => 'non-empty lexical var and array assigned empty',
372 setup => 'my ($x, @a) = 1..4;',
373 code => '($x, @a) = ()',
374 },
375 'expr::aassign::3m_empty' => {
376 desc => 'three my vars assigned empty',
377 setup => '',
378 code => 'my ($x,$y,$z) = ()',
379 },
380 'expr::aassign::3l_empty' => {
381 desc => 'three lexical vars assigned empty',
382 setup => 'my ($x,$y,$z)',
383 code => '($x,$y,$z) = ()',
384 },
385 'expr::aassign::pa_empty' => {
386 desc => 'package array assigned empty',
387 setup => '',
388 code => '@a = ()',
389 },
390 'expr::aassign::pax_empty' => {
391 desc => 'non-empty package array assigned empty',
392 setup => '@a = (1,2,3)',
393 code => '@a = ()',
394 },
395 'expr::aassign::3p_empty' => {
396 desc => 'three package vars assigned empty',
397 setup => '($x,$y,$z) = 1..3;',
398 code => '($x,$y,$z) = ()',
399 },
400
401 # (....) = (1,2,3)
402
403 'expr::aassign::ma_3c' => {
404 desc => 'my array assigned 3 consts',
405 setup => '',
406 code => 'my @a = (1,2,3)',
407 },
408 'expr::aassign::lax_3c' => {
409 desc => 'non-empty lexical array assigned 3 consts',
410 setup => 'my @a = 1..3;',
411 code => '@a = (1,2,3)',
412 },
413 'expr::aassign::llax_3c' => {
414 desc => 'non-empty lexical var and array assigned 3 consts',
415 setup => 'my ($x, @a) = 1..4;',
416 code => '($x, @a) = (1,2,3)',
417 },
418 'expr::aassign::3m_3c' => {
419 desc => 'three my vars assigned 3 consts',
420 setup => '',
421 code => 'my ($x,$y,$z) = (1,2,3)',
422 },
423 'expr::aassign::3l_3c' => {
424 desc => 'three lexical vars assigned 3 consts',
425 setup => 'my ($x,$y,$z)',
426 code => '($x,$y,$z) = (1,2,3)',
427 },
428 'expr::aassign::pa_3c' => {
429 desc => 'package array assigned 3 consts',
430 setup => '',
431 code => '@a = (1,2,3)',
432 },
433 'expr::aassign::pax_3c' => {
434 desc => 'non-empty package array assigned 3 consts',
435 setup => '@a = (1,2,3)',
436 code => '@a = (1,2,3)',
437 },
438 'expr::aassign::3p_3c' => {
439 desc => 'three package vars assigned 3 consts',
440 setup => '($x,$y,$z) = 1..3;',
441 code => '($x,$y,$z) = (1,2,3)',
442 },
443
444 # (....) = @lexical
445
446 'expr::aassign::ma_la' => {
447 desc => 'my array assigned lexical array',
448 setup => 'my @init = 1..3;',
449 code => 'my @a = @init',
450 },
451 'expr::aassign::lax_la' => {
452 desc => 'non-empty lexical array assigned lexical array',
453 setup => 'my @init = 1..3; my @a = 1..3;',
454 code => '@a = @init',
455 },
456 'expr::aassign::llax_la' => {
457 desc => 'non-empty lexical var and array assigned lexical array',
458 setup => 'my @init = 1..3; my ($x, @a) = 1..4;',
459 code => '($x, @a) = @init',
460 },
461 'expr::aassign::3m_la' => {
462 desc => 'three my vars assigned lexical array',
463 setup => 'my @init = 1..3;',
464 code => 'my ($x,$y,$z) = @init',
465 },
466 'expr::aassign::3l_la' => {
467 desc => 'three lexical vars assigned lexical array',
468 setup => 'my @init = 1..3; my ($x,$y,$z)',
469 code => '($x,$y,$z) = @init',
470 },
471 'expr::aassign::pa_la' => {
472 desc => 'package array assigned lexical array',
473 setup => 'my @init = 1..3;',
474 code => '@a = @init',
475 },
476 'expr::aassign::pax_la' => {
477 desc => 'non-empty package array assigned lexical array',
478 setup => 'my @init = 1..3; @a = @init',
479 code => '@a = @init',
480 },
481 'expr::aassign::3p_la' => {
482 desc => 'three package vars assigned lexical array',
483 setup => 'my @init = 1..3; ($x,$y,$z) = 1..3;',
484 code => '($x,$y,$z) = @init',
485 },
486
487 # (....) = @package
488
489 'expr::aassign::ma_pa' => {
490 desc => 'my array assigned package array',
491 setup => '@init = 1..3;',
492 code => 'my @a = @init',
493 },
494 'expr::aassign::lax_pa' => {
495 desc => 'non-empty lexical array assigned package array',
496 setup => '@init = 1..3; my @a = 1..3;',
497 code => '@a = @init',
498 },
499 'expr::aassign::llax_pa' => {
500 desc => 'non-empty lexical var and array assigned package array',
501 setup => '@init = 1..3; my ($x, @a) = 1..4;',
502 code => '($x, @a) = @init',
503 },
504 'expr::aassign::3m_pa' => {
505 desc => 'three my vars assigned package array',
506 setup => '@init = 1..3;',
507 code => 'my ($x,$y,$z) = @init',
508 },
509 'expr::aassign::3l_pa' => {
510 desc => 'three lexical vars assigned package array',
511 setup => '@init = 1..3; my ($x,$y,$z)',
512 code => '($x,$y,$z) = @init',
513 },
514 'expr::aassign::pa_pa' => {
515 desc => 'package array assigned package array',
516 setup => '@init = 1..3;',
517 code => '@a = @init',
518 },
519 'expr::aassign::pax_pa' => {
520 desc => 'non-empty package array assigned package array',
521 setup => '@init = 1..3; @a = @init',
522 code => '@a = @init',
523 },
524 'expr::aassign::3p_pa' => {
525 desc => 'three package vars assigned package array',
526 setup => '@init = 1..3; ($x,$y,$z) = 1..3;',
527 code => '($x,$y,$z) = @init',
528 },
529
530 # (....) = @_;
531
532 'expr::aassign::ma_defary' => {
533 desc => 'my array assigned @_',
534 setup => '@_ = 1..3;',
535 code => 'my @a = @_',
536 },
537 'expr::aassign::lax_defary' => {
538 desc => 'non-empty lexical array assigned @_',
539 setup => '@_ = 1..3; my @a = 1..3;',
540 code => '@a = @_',
541 },
542 'expr::aassign::llax_defary' => {
543 desc => 'non-empty lexical var and array assigned @_',
544 setup => '@_ = 1..3; my ($x, @a) = 1..4;',
545 code => '($x, @a) = @_',
546 },
547 'expr::aassign::3m_defary' => {
548 desc => 'three my vars assigned @_',
549 setup => '@_ = 1..3;',
550 code => 'my ($x,$y,$z) = @_',
551 },
552 'expr::aassign::3l_defary' => {
553 desc => 'three lexical vars assigned @_',
554 setup => '@_ = 1..3; my ($x,$y,$z)',
555 code => '($x,$y,$z) = @_',
556 },
557 'expr::aassign::pa_defary' => {
558 desc => 'package array assigned @_',
559 setup => '@_ = 1..3;',
560 code => '@a = @_',
561 },
562 'expr::aassign::pax_defary' => {
563 desc => 'non-empty package array assigned @_',
564 setup => '@_ = 1..3; @a = @_',
565 code => '@a = @_',
566 },
567 'expr::aassign::3p_defary' => {
568 desc => 'three package vars assigned @_',
569 setup => '@_ = 1..3; ($x,$y,$z) = 1..3;',
570 code => '($x,$y,$z) = @_',
571 },
572
573
574 # (....) = ($lex1,$lex2,$lex3);
575
576 'expr::aassign::ma_3l' => {
577 desc => 'my array assigned lexicals',
578 setup => 'my ($v1,$v2,$v3) = 1..3;',
579 code => 'my @a = ($v1,$v2,$v3)',
580 },
581 'expr::aassign::lax_3l' => {
582 desc => 'non-empty lexical array assigned lexicals',
583 setup => 'my ($v1,$v2,$v3) = 1..3; my @a = 1..3;',
584 code => '@a = ($v1,$v2,$v3)',
585 },
586 'expr::aassign::llax_3l' => {
587 desc => 'non-empty lexical var and array assigned lexicals',
588 setup => 'my ($v1,$v2,$v3) = 1..3; my ($x, @a) = 1..4;',
589 code => '($x, @a) = ($v1,$v2,$v3)',
590 },
591 'expr::aassign::3m_3l' => {
592 desc => 'three my vars assigned lexicals',
593 setup => 'my ($v1,$v2,$v3) = 1..3;',
594 code => 'my ($x,$y,$z) = ($v1,$v2,$v3)',
595 },
596 'expr::aassign::3l_3l' => {
597 desc => 'three lexical vars assigned lexicals',
598 setup => 'my ($v1,$v2,$v3) = 1..3; my ($x,$y,$z)',
599 code => '($x,$y,$z) = ($v1,$v2,$v3)',
600 },
601 'expr::aassign::pa_3l' => {
602 desc => 'package array assigned lexicals',
603 setup => 'my ($v1,$v2,$v3) = 1..3;',
604 code => '@a = ($v1,$v2,$v3)',
605 },
606 'expr::aassign::pax_3l' => {
607 desc => 'non-empty package array assigned lexicals',
608 setup => 'my ($v1,$v2,$v3) = 1..3; @a = @_',
609 code => '@a = ($v1,$v2,$v3)',
610 },
611 'expr::aassign::3p_3l' => {
612 desc => 'three package vars assigned lexicals',
613 setup => 'my ($v1,$v2,$v3) = 1..3; ($x,$y,$z) = 1..3;',
614 code => '($x,$y,$z) = ($v1,$v2,$v3)',
615 },
616
617
618 # (....) = ($pkg1,$pkg2,$pkg3);
619
620 'expr::aassign::ma_3p' => {
621 desc => 'my array assigned 3 package vars',
622 setup => '($v1,$v2,$v3) = 1..3;',
623 code => 'my @a = ($v1,$v2,$v3)',
624 },
625 'expr::aassign::lax_3p' => {
626 desc => 'non-empty lexical array assigned 3 package vars',
627 setup => '($v1,$v2,$v3) = 1..3; my @a = 1..3;',
628 code => '@a = ($v1,$v2,$v3)',
629 },
630 'expr::aassign::llax_3p' => {
631 desc => 'non-empty lexical var and array assigned 3 package vars',
632 setup => '($v1,$v2,$v3) = 1..3; my ($x, @a) = 1..4;',
633 code => '($x, @a) = ($v1,$v2,$v3)',
634 },
635 'expr::aassign::3m_3p' => {
636 desc => 'three my vars assigned 3 package vars',
637 setup => '($v1,$v2,$v3) = 1..3;',
638 code => 'my ($x,$y,$z) = ($v1,$v2,$v3)',
639 },
640 'expr::aassign::3l_3p' => {
641 desc => 'three lexical vars assigned 3 package vars',
642 setup => '($v1,$v2,$v3) = 1..3; my ($x,$y,$z)',
643 code => '($x,$y,$z) = ($v1,$v2,$v3)',
644 },
645 'expr::aassign::pa_3p' => {
646 desc => 'package array assigned 3 package vars',
647 setup => '($v1,$v2,$v3) = 1..3;',
648 code => '@a = ($v1,$v2,$v3)',
649 },
650 'expr::aassign::pax_3p' => {
651 desc => 'non-empty package array assigned 3 package vars',
652 setup => '($v1,$v2,$v3) = 1..3; @a = @_',
653 code => '@a = ($v1,$v2,$v3)',
654 },
655 'expr::aassign::3p_3p' => {
656 desc => 'three package vars assigned 3 package vars',
657 setup => '($v1,$v2,$v3) = 1..3; ($x,$y,$z) = 1..3;',
658 code => '($x,$y,$z) = ($v1,$v2,$v3)',
659 },
660
661
662 # (....) = (1,2,$shared);
663
664 'expr::aassign::llax_2c1s' => {
665 desc => 'non-empty lexical var and array assigned 2 consts and 1 shared var',
666 setup => 'my ($x, @a) = 1..4;',
667 code => '($x, @a) = (1,2,$x)',
668 },
669 'expr::aassign::3l_2c1s' => {
670 desc => 'three lexical vars assigned 2 consts and 1 shared var',
671 setup => 'my ($x,$y,$z) = 1..3;',
672 code => '($x,$y,$z) = (1,2,$x)',
673 },
674 'expr::aassign::3p_2c1s' => {
675 desc => 'three package vars assigned 2 consts and 1 shared var',
676 setup => '($x,$y,$z) = 1..3;',
677 code => '($x,$y,$z) = (1,2,$x)',
678 },
679
680
681 # ($a,$b) = ($b,$a);
682
683 'expr::aassign::2l_swap' => {
684 desc => 'swap two lexical vars',
685 setup => 'my ($a,$b) = (1,2)',
686 code => '($a,$b) = ($b,$a)',
687 },
688 'expr::aassign::2p_swap' => {
689 desc => 'swap two package vars',
690 setup => '($a,$b) = (1,2)',
691 code => '($a,$b) = ($b,$a)',
692 },
693 'expr::aassign::2laelem_swap' => {
694 desc => 'swap two lexical vars',
695 setup => 'my @a = (1,2)',
696 code => '($a[0],$a[1]) = ($a[1],$a[0])',
697 },
698
699 # misc list assign
700
701 'expr::aassign::5l_4l1s' => {
702 desc => 'long list of lexical vars, 1 shared',
703 setup => 'my ($a,$b,$c,$d,$e) = 1..5',
704 code => '($a,$b,$c,$d,$e) = ($a,$a,$c,$d,$e)',
705 },
706
707 'expr::aassign::5p_4p1s' => {
708 desc => 'long list of package vars, 1 shared',
709 setup => '($a,$b,$c,$d,$e) = 1..5',
710 code => '($a,$b,$c,$d,$e) = ($a,$a,$c,$d,$e)',
711 },
712 'expr::aassign::5l_defary' => {
713 desc => 'long list of lexical vars to assign @_ to',
714 setup => '@_ = 1..5',
715 code => 'my ($a,$b,$c,$d,$e) = @_',
716 },
717 'expr::aassign::5l1la_defary' => {
718 desc => 'long list of lexical vars plus long slurp to assign @_ to',
719 setup => '@_ = 1..20',
720 code => 'my ($a,$b,$c,$d,$e,@rest) = @_',
721 },
808ce557
DM
722 'expr::aassign::1l_2l' => {
723 desc => 'single lexical LHS',
724 setup => 'my $x = 1;',
725 code => '(undef,$x) = ($x,$x)',
726 },
727 'expr::aassign::2l_1l' => {
728 desc => 'single lexical RHS',
729 setup => 'my $x = 1;',
9ae0115f
DM
730 code => '($x,$x) = ($x)',
731 },
732 'expr::aassign::2l_1ul' => {
733 desc => 'undef and single lexical RHS',
734 setup => 'my $x = 1;',
808ce557
DM
735 code => '($x,$x) = (undef, $x)',
736 },
a5f48505
DM
737
738
230ee21f
DM
739 'expr::arith::add_lex_ii' => {
740 desc => 'add two integers and assign to a lexical var',
741 setup => 'my ($x,$y,$z) = 1..3;',
742 code => '$z = $x + $y',
743 },
744 'expr::arith::add_pkg_ii' => {
745 desc => 'add two integers and assign to a package var',
746 setup => 'my ($x,$y) = 1..2; $z = 3;',
747 code => '$z = $x + $y',
748 },
749 'expr::arith::add_lex_nn' => {
750 desc => 'add two NVs and assign to a lexical var',
751 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
752 code => '$z = $x + $y',
753 },
754 'expr::arith::add_pkg_nn' => {
755 desc => 'add two NVs and assign to a package var',
756 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
757 code => '$z = $x + $y',
758 },
759 'expr::arith::add_lex_ni' => {
760 desc => 'add an int and an NV and assign to a lexical var',
761 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
762 code => '$z = $x + $y',
763 },
764 'expr::arith::add_pkg_ni' => {
765 desc => 'add an int and an NV and assign to a package var',
766 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
767 code => '$z = $x + $y',
768 },
769
770 'expr::arith::sub_lex_ii' => {
771 desc => 'subtract two integers and assign to a lexical var',
772 setup => 'my ($x,$y,$z) = 1..3;',
773 code => '$z = $x - $y',
774 },
775 'expr::arith::sub_pkg_ii' => {
776 desc => 'subtract two integers and assign to a package var',
777 setup => 'my ($x,$y) = 1..2; $z = 3;',
778 code => '$z = $x - $y',
779 },
780 'expr::arith::sub_lex_nn' => {
781 desc => 'subtract two NVs and assign to a lexical var',
782 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
783 code => '$z = $x - $y',
784 },
785 'expr::arith::sub_pkg_nn' => {
786 desc => 'subtract two NVs and assign to a package var',
787 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
788 code => '$z = $x - $y',
789 },
790 'expr::arith::sub_lex_ni' => {
791 desc => 'subtract an int and an NV and assign to a lexical var',
792 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
793 code => '$z = $x - $y',
794 },
795 'expr::arith::sub_pkg_ni' => {
796 desc => 'subtract an int and an NV and assign to a package var',
797 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
798 code => '$z = $x - $y',
799 },
800
801 'expr::arith::mult_lex_ii' => {
802 desc => 'multiply two integers and assign to a lexical var',
803 setup => 'my ($x,$y,$z) = 1..3;',
804 code => '$z = $x * $y',
805 },
806 'expr::arith::mult_pkg_ii' => {
807 desc => 'multiply two integers and assign to a package var',
808 setup => 'my ($x,$y) = 1..2; $z = 3;',
809 code => '$z = $x * $y',
810 },
811 'expr::arith::mult_lex_nn' => {
812 desc => 'multiply two NVs and assign to a lexical var',
813 setup => 'my ($x,$y,$z) = (1.1, 2.2, 3.3);',
814 code => '$z = $x * $y',
815 },
816 'expr::arith::mult_pkg_nn' => {
817 desc => 'multiply two NVs and assign to a package var',
818 setup => 'my ($x,$y); ($x,$y,$z) = (1.1, 2.2, 3.3);',
819 code => '$z = $x * $y',
820 },
821 'expr::arith::mult_lex_ni' => {
822 desc => 'multiply an int and an NV and assign to a lexical var',
823 setup => 'my ($x,$y,$z) = (1, 2.2, 3.3);',
824 code => '$z = $x * $y',
825 },
826 'expr::arith::mult_pkg_ni' => {
827 desc => 'multiply an int and an NV and assign to a package var',
828 setup => 'my ($x,$y); ($x,$y,$z) = (1, 2.2, 3.3);',
829 code => '$z = $x * $y',
830 },
831
4c2c3128
DM
832 'expr::arith::preinc' => {
833 desc => '++$x',
834 setup => 'my $x = 1;',
835 code => '++$x',
836 },
837 'expr::arith::predec' => {
838 desc => '--$x',
839 setup => 'my $x = 1;',
840 code => '--$x',
841 },
842 'expr::arith::postinc' => {
843 desc => '$x++',
844 setup => 'my $x = 1; my $y',
845 code => '$y = $x++', # scalar context so not optimised to ++$x
846 },
847 'expr::arith::postdec' => {
848 desc => '$x--',
849 setup => 'my $x = 1; my $y',
850 code => '$y = $x--', # scalar context so not optimised to --$x
b52de964
DM
851 },
852
4c2c3128 853
b52de964
DM
854 'loop::for_my_range' => {
855 desc => 'empty for loop with my var and integer range',
856 setup => '',
857 code => 'for my $x (1..10) {}',
4c2c3128
DM
858 },
859
fedf30e1 860];