Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^4: Is undef list assignment a no-op?

by ELISHEVA (Prior)
on Mar 25, 2011 at 15:34 UTC ( #895519=note: print w/replies, xml ) Need Help??

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% --

Replies are listed 'Best First'.
Re^5: Is undef list assignment a no-op?
by BrowserUk (Pope) on Mar 25, 2011 at 15:39 UTC

    Now my results look much like Tux's:

    C:\test>junk74 Rate c a b c 2566/s -- -100% -100% a 1761856/s 68575% -- -18% b 2158325/s 84029% 23% --

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^5: Is undef list assignment a no-op?
by repellent (Priest) on Mar 26, 2011 at 04:46 UTC
    Thanks for the benchmark! (Same thanks goes to Tux and BrowserUk).

    Hmm. This is what I got. I changed to using subs instead:
    use Benchmark qw(cmpthese); my $a1='a'x9999999; my $b1=12345; cmpthese -1,{ und=> sub { sub{ my( undef, $x) = @_ }->( $a1, $b1 ) }, skp=> sub { sub{ my $x = $_[1] }->( $a1, $b1 ) }, var=> sub { sub{ my( $unused, $x ) = @_;}->( $a1, $b1 ) }, }; __END__ Rate var und skp var 50.2/s -- -100% -100% und 516222/s 1027915% -- -32% skp 762291/s 1517942% 48% --

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://895519]
[choroba]: timestamps are hard
[1nickt]: not all all yet
[1nickt]: the stable subversion of each major version on the platform I have in my hands most of the day
[Tux]: choroba can't you up the default stack size to 17?
[1nickt]: and I will maybe add the other subversions
[1nickt]: I am on MacOSX and there is a sore lack of testing resources for CPANTS I think
[choroba]: Tux Why? It works for me with 16 :-)
[Tux]: and the defailt is 15?
[choroba]: sorry, typo. Works for me with 15 which is the default

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2017-09-19 20:08 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (228 votes). Check out past polls.