Instead of dereferencing the entire multilevel structure each time, if you create an array of references to the scalars you are incrementing, then you can iterate over that array and increment the values in the nested hash in 1/6th the time:

#! perl -slw use strict; use Time::HiRes qw[ time ]; my %DB_STATS; $DB_STATS{ COMB }{ $_ } = { Rit=>0, Usc=>0 } for 1 .. 18e5; my $start = time; ++$DB_STATS{ COMB }{ $_ }{Rit} for 1 .. 18e5; printf "Full deref took %.3f seconds\n", time() - $start; my @Rits; $Rits[ $_ ] = \$DB_STATS{ COMB }{ $_ }{Rit} for 1 .. 18e5; $start = time; ++$$_ for @Rits; printf "AoR via alias took %.3f seconds\n", time() - $start; print $DB_STATS{COMB}{1}{Rit}; __END__ C:\test>910049 Full deref took 1.511 seconds AoR via alias took 0.247 seconds 2

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re: About Data Structure and elaboration time (6x faster) by BrowserUk
in thread Apparently strange beahavior that blocks at Filehandle reading by NewMonkMark

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.