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.


In reply to Re^5: how to goto &sysread ? by Tanktalus
in thread how to goto &sysread ? by perl5ever

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.