From: Christian Szegedy Date: 2004-11-07T11:18:39+09:00 Subject: Re: Ruby is a slow performer David G. Andersen wrote: > Disabling the GC doesn't help most of the hash-bound benchmarks > much if they're written properly. The basic loop iteration is > quite fast if you remove the hash access. You can draw your own > conclusions from this. > Hihi, you are so self-confident. I made some tests, and in fact, it turned out, that the hash access is not the problem at all: The original code is: ====================================================== n = (ARGV.shift || 1).to_i hash = {} for i in 1..n hash['%x' % i] = 1 end c = 0 n.downto 1 do |i| c += 1 if hash.has_key? i.to_s end puts c ====================================================== I let it run: chris@gentoo:~$ time h.rb 500000 real 0m8.929s user 0m8.724s sys 0m0.131s No, I try the decimal conversion instead of the hexadecimal: I changed the line hash['%x' % i] = 1 to hash['%d' % i] = 1 chris@gentoo:~$ time h.rb 500000 real 0m9.101s user 0m8.955s sys 0m0.106s And the result is roughly the same. Let's try the functionally equivalent: hash[i.to_s] = 1 chris@gentoo:~$ time h.rb 500000 real 0m4.673s user 0m4.600s sys 0m0.050s So, in fact the hash access is about the same speed as in Perl. The slowdown comes from the formatted output! So much about the reliability of the shootout! Best Regards, Christian