From: "ako..." Date: 2006-08-27T12:05:11+09:00 Subject: Re: map and join or inject? thanks, i did not know that one can count objects using ObjectSpace. it looks like map+join use fewer objects than inject. even though map creates a whole new array. i would expect inject to use fewer objects. strange... konstantin Erik Veenstra wrote: > ---------------------------------------------------------------- > > $ vi test.rb ; cat test.rb > GC.disable > > 1000.times do > (1..1000).map{|s| s.to_s}.join("") > #(1..1000).inject(""){|r, s| s.to_s; r} > end > > count = 0 > ObjectSpace.each_object do > count += 1 > end > p count > > $ ruby test.rb > 1003392 > > ---------------------------------------------------------------- > > $ vi test.rb ; cat test.rb > GC.disable > > 1000.times do > #(1..1000).map{|s| s.to_s}.join("") > (1..1000).inject(""){|r, s| s.to_s; r} > end > > count = 0 > ObjectSpace.each_object do > count += 1 > end > p count > > $ ruby test.rb > 2001392 > > ---------------------------------------------------------------- > > gegroet, > Erik V. - http://www.erikveen.dds.nl/