Just in case this is useful - once upon a time I benchmarked lookup tables. The test looked up every table entry once in random order, then repeated a number of times to get an average. Here's a summary from my notes:

Comparison of lookup tables Range: 2 to 128 byte strings, 10 to 100,000 values 1) By hash key lookup. 2) By iteration over an unsorted array with foreach, exiting at first match. 3) By search algorithms on a sorted array. Results: 1) For small string sizes, and larger strings with fewer than 1000 table values a hash key lookup ranged from 0 to 33% faster than the unsorted array. 2) With 8 byte or longer strings the speed crossover between hash and unsorted array usually occurred with tables between 1000 and 2000 values. At 2000 values the unsorted array lookup speed was: * 20% faster for 8 character strings * 50% faster for 32 character strings * 100% faster for 128 character strings 3) In all cases the sorted array was significantly slower regardless of search algorithm. Worst case was 4% of hash lookup speed, best case 17% of hash lookup speed.

This was done in ActivePerl 5.6 on a 1GHz 'doz 98 machine. Moral: in most cases you may be better off using whatever format your data is already in rather than converting between arrays and hashes.


In reply to Re: Returning position? by hangon
in thread Returning position? by theoya

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.