Small oversight - your benchmark with $unused never makes an assignment from @_. When I fixed the typo and reran it, (undef, $x)= @_ was marginally faster than ($unused, $x) = @_ though not by an amount I consider significant (3%). -- Tested on Perl 5.10.0, system Perl for Debian Lenny, 32bit.
use Benchmark qw(cmpthese);
my $a1='a'x1e6;
my $b1=12345;
cmpthese -1,{
a=>q[ sub{ my( undef, $x) = @_ }->( $a1, $b1 ) ],
b=>q[ sub{ my $x = $_[1] }->( $a1, $b1 ) ],
c=>q[ sub{ my( $unused, $x ) = @_;}->( $a1, $b1 ) ],
};
# Output
Rate c a b
c 649176/s -- -3% -33%
a 670690/s 3% -- -30%
b 963764/s 48% 44% --
Update added Perl version and platform; clarified ranking of results.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|