From: Christian Szegedy Date: 2004-11-07T21:43:38+09:00 Subject: Re: Ruby hashes David G. Andersen wrote: > The ruby version could be improved a bit by pre-declaring the > loop variables, but this is all contained within that .66 seconds > that wasn't the hash access; even if we eliminated it all, > we're still slower than the perl equivalent. Predeclaring: > > 520 eep:~> time ./t-hash2.rb 100 > 1 9999 100 999900 > 3.349u 0.015s 0:03.49 95.9% 6+4524k 0+0io 0pf+0w > > Now, is it the actual hash implementation that's the bottleneck, > or merely the operations required to access it? That I don't know. > But hash[blah] = blah _does_ seem to be measurably slower than > its equivalent in, say, perl. It's not drastic, but it's 20%. > > -Dave > I tried it on my machine, but my numbers are a bit different: chris@gentoo:~/work$ time perl h2.pl 200 1 9999 200 1999800 real 0m5.353s user 0m5.251s sys 0m0.008s chris@gentoo:~/work$ time h2.rb 200 1 9999 200 1999800 real 0m4.384s user 0m4.309s sys 0m0.026s So, on my machine Ruby is 20% faster (not that I would care...). Perl is: v5.8.2 built for i686-linux Ruby is: ruby 1.8.0 (2003-08-04) [i686-linux-gnu] I don't use the binary package, since it is a Gentoo-box and everything is built from source. Best Regards, Christian