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