I like cmpthese results rather than timethese so I've reworked your benchmark a little.
The parameter passing tests were doing a lot of non-parameter passing work so I made the variables global (using our variables) and used the constructed hashes from the first two tests as the test variables for the passing tests.
Rate reference regular
reference 8.00/s -- -8%
regular 8.73/s 9% --
Rate regularPass referencePass
regularPass 7.19/s -- -33%
referencePass 10.7/s 49% --
use strict;
use warnings;
use Benchmark qw(cmpthese);
my %hash;
my $hash;
cmpthese (30, {"regular" => \®ular, "reference" => \&reference});
cmpthese (30, {"regularPass" => \®ularPass, "referencePass" => \&re
+ferencePass});
sub regular {
our %hash;
for my $i (1 .. 100000) {
$hash{$i} = $i;
}
}
sub reference {
our $hash;
for my $i (1 .. 100000) {
$hash->{$i} = $i;
}
}
sub regularPass {
our %hash;
for my $i (1 .. 100000) {
helper(\%hash);
}
}
sub referencePass {
my $hash;
for my $i (1 .. 100000) {
helper($hash);
}
}
sub helper {
my $hash = shift;
}
Perl is Huffman encoded by design.
-
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.
|