On Fri, Jul 13, 2001 at 10:46:30AM -0700, Daniel S. Wilkerson wrote:
> Hash accesses look nice and neat, but lots is going on for each one.
They're not as slow as one might think. For example, here's a
comparison of array and hash lookup speeds. In this test, the array
and the hash both have 338 elements. Each iteration consists of 100
random lookups, the results of which are discarded.
[robin@dev hash-bench]$ perl benchmark-hasharray.pl 2E5
Benchmark: timing 2E5 iterations of array lookup, hash lookup...
array lookup: 42 wallclock secs (43.07 usr + 0.00 sys = 43.07 CPU)
hash lookup: 54 wallclock secs (50.68 usr + 0.01 sys = 50.69 CPU)
Of course variations are possible depending on how many elements
there are, how long the hash keys are and so forth. It's just that
hash access is faster than is often imagined. It's certainly faster
than I expected it to be when I first started trying to collect
data on it.
.robin.