From: Travis Whitton Date: 2003-02-28T03:20:34+09:00 Subject: Re: Is Ruby slower? > Of course, to be fair, in its more traditional strong areas, (regexp matching, hash > access, etc.) Perl shows an equal or better advantage. The only reason Perl's hashes are faster than Ruby's is because Perl uses Bob Jenkins' hashing algorithm, which is _supposedely_ the best known hashing algorithm. Take note, that Perl was using this very simple hashing function until after version 5.005: // Snipped out of the Ruby source code #elif HASH_PERL register int val = 0; while ((c = *string++) != '\0') { val = val*33 + c; } return val + (val>>5); #else It wouldn't take much to use Bob Jenkins' algorithm in Ruby. The current Perl implementation looks like this: #define PERL_HASH(hash,str,len) \ STMT_START { \ register const char *s_PeRlHaSh_tmp = str; \ register const unsigned char *s_PeRlHaSh = (const unsigned char *)s_PeRlHaSh_tmp; \ register I32 i_PeRlHaSh = len; \ register U32 hash_PeRlHaSh = 0; \ while (i_PeRlHaSh--) { \ hash_PeRlHaSh += *s_PeRlHaSh++; \ hash_PeRlHaSh += (hash_PeRlHaSh << 10); \ hash_PeRlHaSh ^= (hash_PeRlHaSh >> 6); \ } \ hash_PeRlHaSh += (hash_PeRlHaSh << 3); \ hash_PeRlHaSh ^= (hash_PeRlHaSh >> 11); \ (hash) = (hash_PeRlHaSh + (hash_PeRlHaSh << 15)); \ } STMT_END All it would take would be converting it over to fit the variables in st.c and adding another preprocessor conditional such as #elif HASH_JENKINS so as not to disturb the 3 other strhash implementations. Anyway, just an idea. You can read about Bob Jenkins hashing function at http://burtleburtle.net/bob/hash/doobs.html Cheers, Travis