in reply to Returning position?
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.
|
|---|