in reply to Re^3: Is undef list assignment a no-op?
in thread Is undef list assignment a no-op?

On my machine (Debian Lenny, Perl 5.10.0 as above) the sequencing and clustering of results is still the same even if our variables are used. In truth the only thing that is changing is the specific values being passed in. There is no fundamental difference in the two benchmarks.

As regards benchmark results, with our variables, the only difference is that the gap between und/var on one hand and $x=$_[1] on the other widens considerably. That is hardly surprising though. ($unused, $x) is copying a 1 million character array into $unused. $x=$_[1] is not.

The result does vividly illustrate that undef in a list is not a no-op. If (undef, $x) = @_ were a no-op its performance should cluster with $x=$_[1], but it doesn't. It acts like ($unused, $x) which copies a very big string. However, that clustering pattern is also identical to the results tux and I got, albeit less dramatically. With either benchmark, if you want to use lists on the left side of an assignment from an array, then you are still no better off using $unused instead of undef.

Are you seeing something different on your machine?

use Benchmark qw(cmpthese); our $a1='a'x1e6; our $b1=12345; cmpthese -1,{ und=>q[ sub{ my( undef, $x) = @_ }->( $a1, $b1 ) ], skp=>q[ sub{ my $x = $_[1] }->( $a1, $b1 ) ], var=>q[ sub{ my( $unused, $x ) = @_;}->( $a1, $b1 ) ], }; #output Rate var und skp var 66.3/s -- -10% -100% und 73.5/s 11% -- -100% skp 945230/s 1424595% 1286780% --