Depends on what we are talking:

Assignment: (reference appears to be consistantly slower than regular)

use Benchmark qw (timethese); timethese(10, {"regular" => \&regular, "reference" => \&reference}); sub regular { my %hash; for my $i (1 .. 100000) { $hash{$i} = $i; } } sub reference { my $hash; for my $i (1 .. 100000) { $hash->{$i} = $i; } }
Benchmark: timing 10 iterations of reference, regular... reference: 8 wallclock secs ( 7.76 usr + 0.16 sys = 7.92 CPU) @ 1 +.26/s (n=1 0) regular: 8 wallclock secs ( 7.20 usr + 0.14 sys = 7.34 CPU) @ 1 +.36/s (n=1 0) Benchmark: timing 10 iterations of reference, regular... reference: 9 wallclock secs ( 7.67 usr + 0.17 sys = 7.84 CPU) @ 1 +.27/s (n=1 0) regular: 8 wallclock secs ( 7.23 usr + 0.08 sys = 7.31 CPU) @ 1 +.37/s (n=1 0)

Assignment + Passing as ref: (reference appears to be faster than regular)

use Benchmark qw (timethese); timethese(10, {"regular" => \&regular, "reference" => \&reference}); sub regular { my %hash; for my $i (1 .. 100000) { $hash{$i} = $i; } helper(\%hash); } sub reference { my $hash; for my $i (1 .. 100000) { $hash->{$i} = $i; } helper($hash); } sub helper { my $hash = shift; }
Benchmark: timing 10 iterations of reference, regular... reference: 8 wallclock secs ( 7.72 usr + 0.14 sys = 7.86 CPU) @ 1 +.27/s (n=1 0) regular: 9 wallclock secs ( 7.91 usr + 0.08 sys = 7.98 CPU) @ 1 +.25/s (n=1 0) Benchmark: timing 10 iterations of reference, regular... reference: 8 wallclock secs ( 7.70 usr + 0.11 sys = 7.81 CPU) @ 1 +.28/s (n=1 0) regular: 9 wallclock secs ( 7.95 usr + 0.06 sys = 8.02 CPU) @ 1 +.25/s (n=1 0)

In reply to Re: Hashes and hash references by pg
in thread Hashes and hash references by Anonymous Monk

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.