From: Gyoung-Yoon Noh Date: 2005-06-10T08:27:33+09:00 Subject: Re: python/ruby benchmark. On 6/10/05, Ara.T.Howard wrote: > > hmmm. since set uses hash yet has at least another level of method calls > that's hard to believe... this is what i'm getting: > > harp:~ > ruby a.rb > ========< set >======== > 3.818156 > > ========< hash >======== > 2.572087 > > > harp:~ > ruby a.rb > ========< set >======== > 3.824544 > > ========< hash >======== > 2.600603 > > > harp:~ > cat a.rb > require 'set' > > def bench label > fork { > GC.disable > STDOUT.sync = true > puts "========< #{ label } >========" > a = Time::now.to_f > yield > b = Time::now.to_f > printf "%f\n", b - a > puts > } > Process::wait > end > > words = IO::readlines('/usr/share/dict/words').map{|word| word.strip} > > set = Set::new > hash = Hash::new > > words.each{|word| set << hash[word] = word} > > bench('set'){ 42.times{ words.each{|word| set.include? word}}} > bench('hash'){ 42.times{ words.each{|word| hash.has_key? word}}} > > > note that times are the time it takes to look up every single word in the list > 42 times. > Oops, I posted absolute stupidity without any context information. Actually, I've been looking into some cases in which ruby is irrationally slow, so 'spellcheck' code come from at that time. See http://shootout.alioth.debian.org/benchmark.php?test=spellcheck&lang=ruby&id=0&sort=fullcpu Anyway, Ara, I got a similar result as you'd presented. Have you tested my code? I doubt 'set' prevails in constructing large data set compared to Hash. In case of 'spellcheck', it seems that the bench would be performed iterative execution of the code. If then, I guess 'set' version probably wins. Sorry for posting without any mention about specific context. Regards, -- http://nohmad.sub-port.net