Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-24 22:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found