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:


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



  • 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.