From: Pit Capitain Date: 2007-01-31T20:08:30+09:00 Subject: Re: Benchmark results Shot (Piotr Szotkowski) schrieb: > Ok, I guess I have a question on what does exactly Benchmark results > mean. Doesn�t the below mean hash_map_sort is actually a bit slower than > hash_sort? This is what I would expect. The advantage of Mauricio's solution is that you can use it even if the Set elements are not comparable to each other. My proposal was meant for your use case with integers as Set elements. > srand 1979 > array = (0..1_000_000).sort_by {rand} > > Benchmark.bmbm do |b| > b.report 'hash_sort' do > Block.new(array).hash_sort > end > b.report 'hash_map_sort' do > Block.new(array).hash_map_sort > end > end With this benchmark, you also measure the time needed to construct the Block instances. If you want to compare the two #hash methods, you should change your benchmark to something like: block = Block.new(array) Benchmark.bmbm do |b| b.report 'hash_sort' do block.hash_sort end b.report 'hash_map_sort' do block.hash_map_sort end end From your benchmark, you can see that it takes a lot of time to compute the hash values. Will your sets contain 1_000_000 elements? How often will they change? How are they created? Maybe you need to cache the hash values or implement a different hash algorithm. Regards, Pit