Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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


Comment on Re^4: Is undef list assignment a no-op?
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://895519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2014-12-18 18:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (59 votes), past polls