[plt-scheme] (Speed) difference between make-hash and make-hasheq

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Aug 23 08:46:41 EDT 2008

At Sat, 23 Aug 2008 14:30:35 +0200, JW wrote:
> Eventually, I solved the problem, by making my
> program run for about 5 minutes straight. Afterwards, I looked at
> solutions other people had written, and I found one that finished in
> less than 20 seconds. I searched for what could be wrong with my
> solution, and I found out that the hash table I used to cache results,
> made the whole thing several times slower.
> 
> Eventually, I found out that using (make-hash) instead of
> (make-hasheq) was the root of all my problems. Why is that? Is it
> normal that there's such a speed difference between using 'equal?' and
> 'eq?'?

No, that's not normal for cases when the `equal?' comparison is easy,
such as for fixnums.

The problem was a bad hashing function for fixnums. Specifically, the
secondary hash code (used for double hashing) was 37 for all fixnums.


The hashing function is now fixed in SVN. On my machine, the example
now runs in about 3.5 seconds using `make-hash', compared to about 2
seconds for `hash-hasheq'.


Thanks for the report!
Matthew



Posted on the users mailing list.