Perl starts with 8 "buckets", very nice and efficient for small hash tables. Each time the hash table doubles all the hash keys have to recomputed (one more bit is added to the binary key). If you know that your hash table is gonna be huge, you can save some computation by setting the number of buckets to be large to begin with by assigning a scalar value to %hash=16384 or whatever, Perl will round to the next higher power of 2 (ie, 16,000 is 16384). This doesn't matter for small hashes, but can save some time for huge ones and avoids the re-computations at doubling boundaries:(8,16,32,64,128,256,512,etc..). For like 90K hash keys, I would start with say 32768 (somewhat less than expected numkeys/2). You have to test to see if this matters at all in your application. I just got a few % increase in one of my apps which didn't amount to much, but then again, if I create something with 120K hash entries, I'm gonna whomp on it for awhile! And the mips to create the table just got dwarfed by what I did with it later. Your mileage may vary!

In reply to Re^3: strange keys with a hash by Marshall
in thread strange keys with a hash by chuckd

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.