From: "Florian Aßmann" Date: 2007-07-17T06:18:10+09:00 Subject: Re: clean nice way (hash) Ok, I think GC is the main problem in my setup :D I tried benchmark and #each behaves much better than #update. #update produces too much overhead... :( The source below can kill your memory since I disabled the GC and only call it manually... Regards Florian require 'benchmark' Benchmark.bm do |x| GC.disable tests = [ Proc.new do hash = ('aaaa'..'zzzz').inject Hash.new do |mem, value| mem[value] = value mem end block = proc { |key, o_val, n_val| {:name => o_val} } x.report('Hash#update') { hash.update(hash, &block) } end ] + [ Proc.new do hash = ('aaaa'..'zzzz').inject Hash.new do |mem, value| mem[value] = value mem end block = proc { |key, value| hash[key] = {:name => value} } x.report('Hash#each') { hash.each(&block) } end ] 12.times do |iteration| if (iteration % 3).zero? GC.start sleep 3 else tests[ rand(2) ].call end end end GC.enable sleep 5