Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Mike Amling Newsgroups: comp.lang.java.programmer Subject: Re: Benchmarking hashcode algorithms Date: Mon, 05 May 2014 11:17:05 -0500 Lines: 42 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net fLkYYJWFpP96Dn7phCejOQvxWP9opc6eiMJvqnURmBQ2GupFv7 Cancel-Lock: sha1:NCNDGNaR6rVHy6Guaj40emht32M= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:28376 On 4/26/14 2:24 PM, Roedy Green wrote: > Here are the latest set of results. There are 100 times faster than in > the previous cut. I was using 1_000_000d to convert from ns to seconds > instead of 1_000_000_000d. Serves me right for not using TimeUnit. > > 1. These are all very fast. For my purposes implementing cache, the > speed is negligible. I have to compute hashes on only 10,000 to > 20,000 files. > > 2. Sun's code works on a string directly. Most hashing require you to > convert the String to a byte first, which is probably as much work a > computing the hash itself. > > 3. Any kind of benchmark code because it does nothing useful can be > optimised out of existence be a clever compiler. I took no measures to > defeat that. > > 4. I also discovered that Adler is not so hot for collisions. > Yep. > ... > > Time to compute 25,000,000 iterations of 32-bit String.hashCode was > 0.393 seconds. > There were 0 collisions in 50,000 filenames > ------ > Time to compute 25,000,000 iterations of 32-bit FNV1a32 was 5.044 > seconds. > There were 1 collisions in 50,000 filenames > ------ > ... Did you write out the code that Java uses to compute String.hashCode, or did you just call s.hashCode()? s.hashCode() could have been precomputed and cached. Did you implement using all 16 bits of each char of the String or only the low-order 8 bits? Mike Amling -- SmFtZXMgTWFkaXNvbiBpcyB1bmRlcnJhdGVkLg==