Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Lies, Damn Lies and Benchmarks

by ysth (Canon)
on Mar 21, 2004 at 23:59 UTC ( [id://338527]=note: print w/replies, xml ) Need Help??


in reply to Lies, Damn Lies and Benchmarks

I'm not sure what your final point is? Doing this:
cmpthese( -2,{ list => sub { &list }, shiftit => sub { &shiftit }, } );
seems just plain broken, and I wouldn't have been surprised if it even made Benchmark roll over and die. You shouldn't be making any assumptions about what is in @_ in your outer sub {}, much less modifiying it.

Trying this:

use Benchmark 'cmpthese'; cmpthese(1, { tryit => sub { $save = \@_ }}); use Data::Dumper; $Data::Dumper::Deparse = 1; print Dumper $save; __END__ $VAR1 = [ 1, sub { $save = \@_; } ];
shows that in fact, cmpthese's parameters are still in @_, and doing:
cmpthese 3, { tryit => sub { push @save, [@_]; shift } }; print Dumper \@save; $VAR1 = [ [ 3, sub { push @save, [@_]; shift @_; } ], [ $VAR1->[0][1] ], [] ];
shows that your shift has blown them away after the first 2 iterations.

Replies are listed 'Best First'.
Re: Re: Lies, Damn Lies and Benchmarks
by xdg (Monsignor) on Mar 22, 2004 at 15:38 UTC

    The final example isn't a recommendation -- it's an explanation of why the original benchmark was doing what it did and why it was giving counterintuitive results. Though I'll agree that it probably could have used a "don't try this at home" kind of warning, given the implications of the PERLSUB excerpt.

    -xdg

    Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-20 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found