From: Brian Candler Date: 2008-09-25T18:25:53+09:00 Subject: Re: Hash optimization question > I haven't looked into Ruby's Hash iterating in detail but it might be > slower because of a general properties of hash tables: they are > usually bigger (i.e. have more buckets) than the number of elements in > the hash to allow for efficient hashing. Now if there are no links > between hash entries (whose maintenance I believe would increase > insertion overhead) iteration needs to access each hash bucket even > those with no data in. That might account for the slower runtimes. 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. (However, depending on this feature is a good way of writing code which won't run properly in 1.8) -- Posted via http://www.ruby-forum.com/.