From: Roger Pack Date: 2008-09-25T06:08:11+09:00 Subject: Re: Hash optimization question > Well indeed I would suggest to anyone having problems with performance > of small hashes to have a look at Array#assoc and #rassoc. The only > problem is I do not know up to which number of pairs this behaves > well. I guess n<20 should be quite safe. Maybe I will find some time > to benchmark this later. So our goal is to see if Array#assoc is "about as fast as hash based lookup" >> a = {1 => 2, 2 => 3 } >> b = [[1, 2], [2, 3]] >> Benchmark.measure { 1000000.times { a[2] }} => # >> Benchmark.measure { 1000000.times { b.assoc 1 }} => # faster than a hash :) >> Benchmark.measure { 1000000.times { b.assoc 2 }} => # Quite a bit slower. So with only 2 entries #assoc is slower. Oh well, we do what we can. -=R -- Posted via http://www.ruby-forum.com/.