Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

for what i's worth...

#!/usr/local/bin/perl use strict; use warnings; use Benchmark qw[ cmpthese timethese ]; package Benchmark; my @keys = ('s', 'm' x 10, 'l' x 100, 'h' x 1_000, 'r' x 100_000); sub test { my ($iters, $key) = @_; my %hash = (); # regardless of which key we use, build all the keys so the time # needed to clone a big string doesn't overshadow the time to clon +e # a small string. for (my $i = 0; $i < $iters; $i++) { $hash { (map { $_.$i } @keys)[$key] } = undef; } } my $many = 100; cmpthese(5*$many, { 'short' => sub { test($many, 0) }, 'medium' => sub { test($many, 1) }, 'long' => sub { test($many, 2) }, 'huge' => sub { test($many, 3) }, 'ridiculous' => sub { test($many, 4) }, }); __END__ laptop:~> monk.pl Benchmark: timing 500 iterations of huge, long, medium, ridiculous, sh +ort... laptop:~> monk.pl Benchmark: timing 500 iterations of huge, long, medium, ridiculous, sh +ort... huge: 31 wallclock secs (31.57 usr + 0.00 sys = 31.57 CPU) @ 15 +.84/s (n=500) long: 32 wallclock secs (30.39 usr + 0.03 sys = 30.42 CPU) @ 16 +.44/s (n=500) medium: 33 wallclock secs (30.03 usr + 0.01 sys = 30.04 CPU) @ 16 +.64/s (n=500) ridiculous: 187 wallclock secs (159.85 usr + 18.47 sys = 178.32 CPU) @ + 2.80/s (n=500) short: 30 wallclock secs (30.09 usr + 0.02 sys = 30.11 CPU) @ 16 +.61/s (n=500) Rate ridiculous huge long short medi +um ridiculous 2.80/s -- -82% -83% -83% -8 +3% huge 15.8/s 465% -- -4% -5% - +5% long 16.4/s 486% 4% -- -1% - +1% short 16.6/s 492% 5% 1% -- - +0% medium 16.6/s 494% 5% 1% 0% +--

which seems to indicate that the key size can affect things, but only if you're dealing with seriously huge keys.

Note:

  • zentara's benchmark doesn't take into account the fact that building up a big string takes longer then building up a short string .. hence i tried to make sure the only different between the tests was which key was added to the hash.
  • sleepingsquirrel's benchmark reuses two keys over and over (which does test the time spent hashing the keys, and is fair about the time spent building the string) so he doens't consider the added cost of storing lots of big keys. some people don't consider memory utilization a valid thing to consider when doing a Benchmark like this, but if it takes longer to execute access data because the data structure is really huge, that seems like a fair thing to consider.

In reply to Re: code execution speed and variable name length by hossman
in thread code execution speed and variable name length by zentara

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? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2022-12-01 17:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?