Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #28241

Re: Benchmarking hashcode algorithms

From Roedy Green <see_website@mindprod.com.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Benchmarking hashcode algorithms
Date 2014-04-26 12:24 -0700
Organization Canadian Mind Products
Message-ID <b71ol91g81ig0u3o2rkgete4ltj9m100r5@4ax.com> (permalink)
References <klnnl9ls2ovfnt6slsp4hsh6tcig3j5ka9@4ax.com>

Show all headers | View raw


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.

5. I expected Sun's String.hashCode to be fast, but to have lots of
collisions. It had none.

6. The speed penalty of the cryptographic hashes is not nearly a high
as I expected.

7. Whoever writes these functions is gradually making them faster.


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
------
Time to compute 25,000,000 iterations of 64-bit FNV1a64 was 4.217
seconds.
There were 0 collisions in 50,000 filenames
------
Time to compute 25,000,000 iterations of 32-bit SunCRC32 was 6.133
seconds.
There were 1 collisions in 50,000 filenames
------
Time to compute 25,000,000 iterations of 32-bit Adler was 6.327
seconds.
There were 946 collisions in 50,000 filenames
------
Time to compute 25,000,000 iterations of 128-bit MD5 was 12.967
seconds.
There were 0 collisions in 50,000 filenames
------
Time to compute 25,000,000 iterations of 160-bit SHA-1 was 23.390
seconds.
There were 0 collisions in 50,000 filenames
------
Time to compute 25,000,000 iterations of 160-bit SHA was 22.690
seconds.
There were 0 collisions in 50,000 filenames
------
Time to compute 25,000,000 iterations of 256-bit SHA-256 was 30.003
seconds.
There were 0 collisions in 50,000 filenames
------
Time to compute 25,000,000 iterations of 384-bit SHA-384 was 30.902
seconds.
There were 0 collisions in 50,000 filenames
------
Time to compute 25,000,000 iterations of 512-bit SHA-512 was 30.538
seconds.
There were 0 collisions in 50,000 filenames
------
Time to compute 25,000,000 iterations of 16-bit SunCRC16 was 34.809
seconds.
There were 14,949 collisions in 50,000 filenames
------
Time to compute 25,000,000 iterations of 128-bit MD2 was 178.489
seconds.
There were 0 collisions in 50,000 filenames
------

-- 
Roedy Green Canadian Mind Products http://mindprod.com
Computers are like Old Testament gods; lots of rules and no mercy. 
~ Joseph Campbell (born: 1904-03-26 died: 1987-10-31 at age: 83)

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Benchmarking hashcode algorithms Roedy Green <see_website@mindprod.com.invalid> - 2014-04-26 09:49 -0700
  Re: Benchmarking hashcode algorithms Marcel Müller <news.5.maazl@spamgourmet.org> - 2014-04-26 18:54 +0200
  Re: Benchmarking hashcode algorithms Roedy Green <see_website@mindprod.com.invalid> - 2014-04-26 12:24 -0700
    Re: Benchmarking hashcode algorithms Mike Amling <mamling@chaff.us> - 2014-05-05 11:17 -0500
      Re: Benchmarking hashcode algorithms Roedy Green <see_website@mindprod.com.invalid> - 2014-05-16 16:27 -0700
        Re: Benchmarking hashcode algorithms Silvio <silvio@internet.com> - 2014-05-20 17:32 +0200
      Re: Benchmarking hashcode algorithms Roedy Green <see_website@mindprod.com.invalid> - 2014-05-16 16:28 -0700

csiph-web