Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^5: how to goto &sysread ?

by Tanktalus (Canon)
on Jul 26, 2011 at 14:06 UTC ( [id://916777]=note: print w/replies, xml ) Need Help??


in reply to Re^4: how to goto &sysread ?
in thread how to goto &sysread ?

Apparently, which is slower depends on your version of perl... :-)

Here's the benchmark code I used. Now, it's not entirely fair because I'm not testing with a long list of parameters - Benchmark is going to only pass in a single parameter. However, it's a start.

#!/usr/bin/perl sub dest { return 1 } # don't want it optimised away use Benchmark qw(:all); cmpthese(-1, { goto => sub { goto &dest; }, call => sub { return dest(@_); }, callamp => sub { return &dest; }, });
And the results? They depend on the version of perl. Using just the oldest and newest perls I have:
$ perl5.8.8 x.pl Rate call callamp goto call 4283398/s -- -9% -29% callamp 4693114/s 10% -- -22% goto 5996757/s 40% 28% -- $ perl5.14.1 x.pl Rate call goto callamp call 4633858/s -- -9% -12% goto 5119310/s 10% -- -2% callamp 5242879/s 13% 2% --
Of course, nothing of import is actually happening, the code in the called function will likely completely overwhelm the calling, so (and I'm sure you, ikegami, know this) don't base which one you use on the performance - there is no real significant difference - even the slowest one in perl 5.8.8 only takes 2.3e-7 seconds (on my CPU), which amounts to a couple hundred CPU cycles. Any REAL work you're doing will so completely overwhelm this that the so-called "savings" between calling it one way vs another will be nothing more than noise. Use the one that does what you mean, the maintainers (which likely will include yourself 6+ months from now) will thank you.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found