From: Roger Pack Date: 2008-09-27T05:30:36+09:00 Subject: Re: Hash optimization question > Aside: ruby-1.9 keeps links between hash entries, exactly for the > purpose of faster iteration. It also has the potentially useful > side-effect that hashes iterate in the same order that the entries were > inserted. Interesting. It appears that whatever the internal linking mechanism, it still differs from Array#each speed-wise: 1.8.6 Hash: >> Benchmark.measure { a = {:a => :b, :c => :d}; 100_000.times { a.each {} }} => # 1.8.6 Array: >> Benchmark.measure { a = [[:a => :b], [:c => :d]]; 100_000.times { a.each {} }} => # so 0.17 to 0.7 s and on 1.9 Hash: >> Benchmark.measure { a = {:a => :b, :c => :d}; 100_000.times { a.each {} }} => # 1.9 Array: >> Benchmark.measure { a = [[:a, :b], [:c, :d]]; 100_000.times { a.each {} }} => # so 0.14 to 0.05 s The numbers seem very similar, comparison wise, to each other. -=R -- Posted via http://www.ruby-forum.com/.