SMhasher

Alternative timings with an old Macbook Air 2010 Intel i7-4650 1.7GHz laptop:

Hash function MiB/sec cycl./hash cycl./map size Quality problems
donothing32 38533817.23 4.61 - 13 test NOP
donothing64 22932681.43 4.89 - 13 test NOP
donothing128 24105245.38 4.43 - 13 test NOP
NOP_OAAT_read64 3575.94 26.89 - 47 test NOP
BadHash 731.62 70.51 - 47 test FAIL
sumhash 20779.53 24.05 - 363 test FAIL
sumhash32 78304.28 16.28 - 863 UB, test FAIL
multiply_shift 5895.97 19.80 382.12 (20) 345 fails all tests
pair_multiply_shift 9331.73 18.67 363.68 (15) 609 fails all tests

crc32 565.07 91.72 393.32 (46) 422 insecure, 8590x collisions, distrib
md5_32a 415.24 503.28 900.52 (4) 4419 8590x collisions, distrib
sha1_32a 719.32 777.42 - 5126 collisions, 36.6% distrib
md5-128 415.28 503.48 877.35 (37) 4419
sha1-160 730.56 790.86 1185.25 (40) 5126 Comb/Cyclic low32
sha2-224 150.54 1279.21 - Cyclic low32
sha2-224_64 148.80 1156.04 1222.48 (60) Cyclic low32
sha2-256 251.52 831.08 1272.69 (90)
sha2-256_64 251.33 830.84 1221.11 (53)
sha1ni 2019.96 135.84 564.40 (6) 989 insecure,sanity, Permutation, Zeroes, amd epyc only
sha1ni_32 2019.94 136.82 589.46 (1) 989 insecure,sanity, Permutation, Zeroes, TwoBytes, amd epyc only
sha2ni-256 1906.77 145.47 603.08 (22) 4241 insecure,sanity, Permutation, Zeroes, amd epyc only
sha2ni-256_64 1920.36 145.47 603.08 (2) 4241 insecure,sanity, Permutation, Zeroes, TwoBytes, amd epyc only
blake3_c 1835.56 232.42 558.95 (40) no 32bit portability
rmd128 401.44 682.00 1045.48 (32)
rmd160 265.01 913.37 1278.42 (70)
rmd256 477.39 625.96 1039.25 (46)
blake2s-128 306.43 670.08 995.27 (40)
blake2s-160 295.85 676.37 1028.40 (82)
blake2s-224 295.13 687.75 1010.64 (45)
blake2s-256 304.74 671.03 995.03 (69)
blake2s-256_64 298.69 668.64 1063.35 (52)
blake2b-160 544.33 746.71 1105.17 (50)
blake2b-224 531.80 746.17 1067.60 (37)
blake2b-256 540.02 743.87 1041.36 (64) Sparse high 32-bit
blake2b-256_64 536.14 755.14 1074.85 (97)
asconhashv12 190.38 680.69 894.89 (22)
asconhashv12_64 190.63 318.57 542.07 (15)
sha3-256 87.23 7231.08 - PerlinNoise
sha3-256_64 56.18 6831.13 - PerlinNoise
hasshe2 1650.87 87.66 484.20 (87) 445 Permutation,TwoBytes,Zeroes,Seed
poly_1_mersenne 1298.15 67.21 416.20 (6) 479 fails most tests
poly_2_mersenne 1264.75 74.19 495.63 (102) 479
poly_3_mersenne 1176.67 80.55 472.25 (93) 479
poly_4_mersenne 1236.23 87.62 492.25 (99) 479
tabulation32 10561.97 24.14 368.93 (26) 848 collisions
tabulation 12273.85 30.84 386.80 (20) 554
crc32_hw 8646.60 28.56 449.47 (85) 653 insecure, 100% bias, collisions, distrib, machine-specific (x86 SSE4.2)
crc32_hw1 23549.80 36.63 485.65 (98) 671 insecure, 100% bias, collisions, distrib, machine-specific (x86 SSE4.2)
crc64_hw 9069.30 29.79 437.68 (40) 652 insecure, 100% bias, collisions, distrib, machine-specific (x64 SSE4.2)
crc32_pclmul 880479.72 9.52 979.52 (309) 481 insecure, 100% bias, collisions, distrib, machine-specific (x86 PCLMUL)
o1hash 5525178.01 15.81 457.98 (78) 101 insecure, zeros, fails all tests
fibonacci 15997.12 24.16 1145.09 (243) 1692 UB, zeros, fails all tests
FNV1a 778.72 63.87 518.63 (100) 204 zeros, fails all tests
FNV1A_Totenschiff 6588.64 30.64 460.29 (87) 270 UB, zeros, fails all tests
FNV1A_Pippip_Yurii 6524.14 31.79 478.29 (101) 147 UB, sanity, fails all tests
FNV1a_YT 14785.01 25.69 437.91 (80) 321 UB, fails all tests
FNV2 6549.81 36.56 452.32 (105) 278 fails all tests
FNV64 719.93 65.16 445.18 (84) 79 fails all tests
FNV128 719.93 65.16 445.18 (84) 171 fails all tests
fletcher2 17735.18 24.30 693.39 (154) 248 UB, fails all tests
fletcher4 16977.39 24.38 597.59 (104) 371 UB, fails all tests
bernstein 936.97 51.70 382.62 (18) 41 fails all tests
sdbm 851.76 61.97 408.42 (20) 41 fails all tests
x17 505.13 97.80 492.96 (90) 79 99.98% bias, fails all tests
JenkinsOOAT 487.34 128.71 587.27 (89) 153 53.5% bias, fails all tests
JenkinsOOAT_perl 459.65 112.97 624.58 (116) 65 1.5-11.5% bias, 7.2x collisions, LongNeighbors
MicroOAAT 536.50 86.11 687.88 (185) 68 100% bias, distrib
beamsplitter 619.02 675.57 967.83 (49) UB, too many bad seeds
discohash 2951.01 213.86 346.87 (4) 1294
pearsonhash64 400.88 124.53 456.56 (74) Avalanche, Seed, SSSE3 only. broken MSVC
pearsonhash128 405.76 123.17 392.48 (15) Avalanche, Seed, SSSE3 only. broken MSVC
pearsonhash256 403.93 127.41 403.75 (28) Avalanche, Seed, SSSE3 only. broken MSVC
VHASH_32 7713.21 68.96 524.57 (90) 1231 sanity, Seed, MomentChi2
VHASH_64 7814.47 81.23 503.58 (21) 1231 sanity, Seed, Sparse
farsh32 14053.09 74.29 245.33 (3) 944 insecure: AppendedZeroes, collisions+bias, MomentChi2, LongNeighbors
farsh64 7216.29 130.30 302.44 (3) 944 insecure: AppendedZeroes, collisions+bias, MomentChi2, LongNeighbors
jodyhash32 1750.56 37.83 502.36 (79) 102 bias, collisions, distr, LongNeighbors
jodyhash64 3009.97 32.86 441.36 (104) 118 bias, collisions, distr, LongNeighbors
lookup3 3079.37 29.59 403.49 (28) 341 UB, 28% bias, collisions, 30% distr
superfast 3065.72 33.07 413.25 (34) 210 UB, 91% bias, 5273.01x collisions, 37% distr, BIC
MurmurOAAT 601.53 77.62 393.01 (23) 47 collisions, 99.998% distr., BIC, LongNeighbors
Crap8 3989.84 26.98 444.67 (71) 342 UB, 2.42% bias, collisions, 2% distrib
Murmur1 2699.64 34.90 382.10 (11) UB, fails all tests, 1 bad seed
Murmur2 3892.04 29.77 387.93 (30) 358 UB, 1.7% bias, 81x coll, 1.7% distrib, BIC
Murmur2A 4045.34 32.95 384.54 (23) 407 UB, 12.7% bias, LongNeighbors
Murmur2B 8071.01 32.63 380.58 (20) 433 UB, 1.8% bias, collisions, 3.4% distrib, BIC
Murmur2C 5453.95 32.38 381.19 (28) 444 UB, 91% bias, collisions, distr, BIC, LongNeighbors
Murmur3A 3248.10 37.60 391.37 (22) 351 UB, Moment Chi2 69
PMurHash32 3259.80 36.96 381.88 (26) 1862 Moment Chi2 69
Murmur3C 3772.31 45.29 393.32 (22) 859 UB, LongNeighbors, DiffDist
PMPML_32 10950.76 87.30 432.56 (20) 1084 Avalanche >512, unseeded: Seed, MomentChi2
PMPML_64 12574.53 37.84 380.22 (26) 1305 unseeded: Seed, MomentChi2
xxHash32 7186.02 37.21 386.30 (63) 738 LongNeighbors, collisions with 4bit diff, MomentChi2 220
metrohash64_1 17609.59 34.48 379.24 (22) 624 UB, LongNeighbors, BIC, MomentChi2
metrohash64_2 17769.15 35.01 387.19 (20) 627 UB, LongNeighbors
metrohash64crc_1 27331.04 37.52 365.84 (18) 632 UB, cyclic collisions 8 byte, BIC, MomentChi2, machine-specific (x64 SSE4.2)
metrohash64crc_2 25247.22 41.63 413.02 (55) 632 UB, cyclic collisions 8 byte, BIC, machine-specific (x64 SSE4.2)
metrohash128_1 16755.69 42.09 376.58 (19) 773 UB, LongNeighbors
metrohash128_2 17559.43 42.16 348.30 (14) 773 UB, LongNeighbors
cmetrohash64_1o 13988.03 38.02 346.37 (19) 3506 LongNeighbors, MomentChi2
cmetrohash64_1 18199.72 35.68 360.79 (22) 652 LongNeighbors, BIC, MomentChi2
cmetrohash64_2 14207.75 41.29 407.54 (55) 655 LongNeighbors
City64noSeed 12403.53 31.57 407.61 (33) 1038 Avalanche, Sparse, TwoBytes, MomentChi2, Seed
City64 13776.78 39.88 437.52 (44) 1120 Sparse, TwoBytes
t1ha1_64le 15170.95 26.44 368.19 (29) 517 Avalanche
t1ha1_64be 12353.36 28.27 391.71 (30) 555 Avalanche
t1ha0_32le 8861.18 36.12 394.19 (25) 509 Sparse, LongNeighbors
t1ha0_32be 7829.71 36.12 379.61 (26) 533 Sparse, LongNeighbors
t1ha2_stream 5740.08 90.27 599.15 (124) 1665 Sparse, Permutation, LongNeighbors
t1ha2_stream128 5521.03 104.96 577.67 (120) 1665 Sparse, Permutation, LongNeighbors
aesnihash 2963.39 71.24 217.73 (3) 1209 fails many tests, machine-specific (x64 AES-NI)
falkhash 36531.40 101.39 482.99 (43) 264 Sparse, LongNeighbors, machine-specific (x64 AES-NI)
MeowHash 21515.37 84.13 1578.54 (649) 1764 Sparse, machine-specific (x64 AES-NI)
MeowHash64low 21910.32 84.50 681.72 (70) 1764 Sparse, machine-specific (x64 AES-NI)
MeowHash32low 20821.45 87.60 780.33 (147) 1764 Sparse, machine-specific (x64 AES-NI)
tifuhash_64 69.06 814.05 858.49 (34) 276
floppsyhash 62.76 1099.01 1421.59 (57) 623
chaskey 669.31 159.36 583.90 (117) 1609 PerlinNoise
SipHash 945.95 133.18 523.95 (104) 1071
HalfSipHash 728.61 95.76 502.84 (108) 700 zeroes
GoodOAAT 961.73 65.66 548.21 (65) 237
pearsonbhash64 2321.28 71.86 390.69 (18) 683
pearsonbhash128 2221.71 79.17 400.51 (20) 1134
pearsonbhash256 1850.94 91.40 414.29 (19) 844
prvhash64_64m 3848.16 35.92 373.19 (20) 349
prvhash64_64 3895.65 36.34 375.70 (11) 384
prvhash64_128 3642.90 59.02 389.59 (13) 718
prvhash64s_64 8826.27 179.47 469.27 (23) 2640
prvhash64s_128 9307.53 227.58 542.27 (27) 2799
SipHash13 1829.99 94.80 499.35 (105) 778 0.9% bias
TSip 4218.38 52.96 432.65 (54) 519 !msvc
seahash 7848.36 62.64 506.21 (110) 871 PerlinNoise, !msvc
seahash32low 8214.42 63.29 482.25 (89) 871 PerlinNoise, !msvc
clhash 15065.60 69.98 490.26 (105) 1809 PerlinNoise, machine-specific (x64 SSE4.2)
HighwayHash64 12276.60 91.89 494.56 (30) 2546
Murmur3F 5535.99 46.29 442.89 (81) 699 UB
fasthash32 5861.46 43.13 457.54 (80) 566 UB
fasthash64 7317.82 33.13 375.12 (28) 509 UB, Moment Chi2 5159 !
MUM 9550.97 34.82 444.64 (90) 1912 UB, too many bad seeds, machine-specific (32/64 differs)
MUMlow 9384.26 40.25 458.62 (86) 1912 UB, 5 bad seeds
xmsx32 2039.10 46.39 249.30 (7) 192 2 bad seeds
mirhash 6661.42 39.67 443.93 (80) 1112 2^36 bad seeds, UB, LongNeighbors, machine-specific (32/64 differs)
mirhash32low 6836.60 38.37 470.91 (105) 1112 4 bad seeds, UB, Cyclic, LongNeighbors, machine-specific (32/64 differs)
mirhashstrict 2992.15 54.25 468.47 (90) 1112
mirhashstrict32low 2980.73 53.22 453.53 (76) 1112 1 bad seed, MomentChi2 9
mx3 8449.64 44.52 447.95 (99) 734 UB
pengyhash 9915.52 76.94 539.63 (68) 421
City32 6114.53 37.34 398.04 (23) 1319
City64low 11526.56 45.80 442.04 (24) 1120
City128 12301.53 54.23 415.92 (15) 1841
CityCrc128 16203.64 58.52 491.33 (100) 295
FarmHash32 11957.83 42.76 520.79 (108) 11489 machine-specific (x64 SSE4/AVX)
FarmHash64 10709.53 47.27 506.20 (107) 3758
FarmHash128 11281.52 54.93 440.44 (26) 163
farmhash32_c 19718.60 47.50 544.34 (107) 762 machine-specific (x64 SSE4/AVX)
farmhash64_c 11742.66 44.03 447.32 (74) 3688
farmhash128_c 11340.55 56.54 719.54 (134) 1890
metrohash64 17666.95 34.59 362.91 (27) 624 LongNeighbors
metrohash128 17554.51 41.88 373.34 (20) 624 UB
metrohash128crc_1 22823.55 51.88 370.87 (40) 723 UB, machine-specific (x64 SSE4.2)
metrohash128crc_2 27168.94 50.14 437.24 (72) 723 UB, machine-specific (x64 SSE4.2)
xxHash64 9931.70 53.58 636.43 (105) 1999
Spooky32 10203.46 59.90 644.04 (100) 2221 UB
Spooky64 8248.04 58.52 440.67 (95) 2221 UB
Spooky128 12227.52 52.50 480.24 (98) 2221 UB
SpookyV2_32 16816.08 45.12 472.80 (19) 2069
SpookyV2_64 16879.61 45.18 490.62 (35) 2069
SpookyV2_128 16326.13 48.59 486.83 (124) 2069
t1ha2_atonce 13024.80 40.82 516.35 (87) 541
t1ha2_atonce128 10795.46 54.85 465.65 (64) 613 LongNeighbors
t1ha0_aes_noavx 18322.64 39.16 488.58 (105) 925 LongNeighbors, machine-specific (x86 AES-NI)
t1ha0_aes_avx1 18294.64 38.73 432.99 (96) 843 LongNeighbors, machine-specific (x64 AVX)
t1ha0_aes_avx2 26418.73 39.53 457.81 (83) 792 LongNeighbors, machine-specific (x64 AVX2)
xxh3 29201.41 29.59 411.98 (71) 744 Moment Chi2 14974, BIC
xxh3low 10161.09 29.16 476.80 (94) 756 Moment Chi2 1.8e+9 !
xxh128 26202.50 34.04 464.67 (113) 1012 Moment Chi2 14974
xxh128low 25254.74 35.53 458.54 (103) 1012 Moment Chi2 14974, BIC
MeowHash 21515.37 84.13 1578.54 (649) 1764 Sparse low32, machine-specific (x64 AES-NI)
MeowHash32low 20821.45 87.60 780.33 (147) 1764 Sparse, machine-specific (x64 AES-NI)
wyhash 25331.37 21.65 384.19 (35) 474
wyhash32 2532.89 37.95 222.17 (4) 426 4 bad and broken seeds, 32-bit
wyhash32low 24758.90 21.59 380.88 (29) 474 5 bad seeds
umash32 15939.18 44.41 464.61 (98) 1530
umash32_hi 15041.87 52.90 429.76 (24) 1530
umash64 14058.41 46.74 510.45 (109) 1530
umash128 7010.13 50.60 472.99 (106) 1530
halftime_hash64 8236.81 57.23 399.89 (20) 1530
halftime_hash128 16053.93 61.17 434.48 (28) 1530
halftime_hash256 27912.23 61.62 452.26 (23) 1530
halftime_hash512 19077.00 77.91 434.56 (14) 1530
nmhash32 12544.62 55.36 616.33 (49) 2445
nmhash32x 13986.77 41.40 628.08 (61) 1494
Other timings:

Summary

I added some SSE assisted hashes and fast intel/arm CRC32-C and AES HW variants, but not the fastest crcutil yet. See our crcutil results. See also the old https://code.google.com/p/smhasher/w/list.

So the fastest hash functions on x86_64 without quality problems are:

Hash functions for symbol tables or hash tables typically use 32 bit hashes, for databases, file systems and file checksums typically 64 or 128bit, for crypto now starting with 256 bit.

Typical median key size in perl5 is 20, the most common 4. Similar for all other dynamic languages. See github.com/rurban/perl-hash-stats

When used in a hash table the instruction cache will usually beat the CPU and throughput measured here. In my tests the smallest FNV1A beats the fastest crc32_hw1 with Perl 5 hash tables. Even if those worse hash functions will lead to more collisions, the overall speed advantage and inline-ability beats the slightly worse quality. See e.g. A Seven-Dimensional Analysis of Hashing Methods and its Implications on Query Processing for a concise overview of the best hash table strategies, confirming that the simplest Mult hashing (bernstein, FNV*, x17, sdbm) always beat "better" hash functions (Tabulation, Murmur, Farm, ...) when used in a hash table.

The fast hash functions tested here are recommendable as fast for file digests and maybe bigger databases, but not for 32bit hash tables. The "Quality problems" lead to less uniform distribution, i.e. more collisions and worse performance, but are rarely related to real security attacks, just the 2nd sanity zeroes test against \0 invariance is security relevant.

Columns

MiB/sec: The average of the Bulk key speed test for alignments 0-7 with 262144-byte keys. The higher the better.

cycl./hash: The average of the Small key speed test for 1-31 byte keys. The smaller the better.

cycl./map: The result of the Hashmap test for /usr/dict/words with std::unordered_map get queries, with the standard deviation in brackets. This tests the inlinability of the hash function (see size). The smaller the better.

size: The object size in byte on AMD64. This affects the inlinability in e.g. hash tables. The smaller the better.

Quality problems: See the failures in the linked doc. The less the better.

Other

SECURITY

The hash table attacks described in SipHash against City, Murmur or Perl JenkinsOAAT or at Hash Function Lounge are not included here.

Such an attack avoidance cannot be the problem of the hash function, but only the hash table collision resolution scheme. You can attack every single hash function, even the best and most secure if you detect the seed, e.g. from language (mis-)features, side-channel attacks, collision timings and independly the sort-order, so you need to protect your collision handling scheme from the worst-case O(n), i.e. separate chaining with linked lists. Linked lists chaining allows high load factors, but is very cache-unfriendly. The only recommendable linked list scheme is inlining the key or hash into the array. Nowadays everybody uses fast open addressing, even if the load factor needs to be ~50%, unless you use Cuckoo Hashing.

I.e. the usage of SipHash for their hash table in Python 3.4, ruby, rust, systemd, OpenDNS, Haskell and OpenBSD is pure security theatre. SipHash is not secure enough for security purposes and not fast enough for general usage. Brute-force generation of ~32k collisions need 2-4m for all these hashes. siphash being the slowest needs max 4m, other typically max 2m30s, with <10s for practical 16k collision attacks with all hash functions. Using Murmur is usually slower than a simple Mult, even in the worst case. Provable secure is only uniform hashing, i.e. 2-5 independent Mult or Tabulation, or using a guaranteed logarithmic collision scheme (a tree) or a linear collision scheme, such as Robin Hood or Cockoo hashing with collision counting.

One more note regarding security: Nowadays even SHA1 can be solved in a solver, like Z3 (or faster ones) for practical hash table collision attacks (i.e. 14-20 bits). All hash functions with less than 160 bits tested here cannot be considered "secure" at all.

The '' vulnerability attack with binary keys is tested in the 2nd Sanity Zero test.

CRYPTO

The official NIST hash function testsuite does not do such extensive statistical tests, to search for weak ranges in the bits. Also crypto does not change the initial state, which we do here for our random 32bit seed. Crypto mostly cares about unreversable key -> hash functions without changing the initial fixed state and timings/sidechannel attacks.

The NIST "Cryptographic Algorithm Validation Program" (CAVP) involves the testing of the implementations of FIPS-approved and NIST-recommended cryptographic algorithms. During the NIST SHA-3 competition, the testing methodology was borrowed from the "CAVP", as the KATs and MCTs of the SHA-3 Competition Test Suite were based on the CAVP tests for SHA-2. In addition to this, the “Extremely Long Message Test,” not present in the CAVP for SHA-2, required the submitters to generate the hash value corresponding to a message with a length of 1 GiB. “NIST - Cryptographic Algorithm Validation Program (CAVP),” June 2017. Available: http://csrc.nist.gov/groups/STM/cavp (No testing source code provided, just high-level descriptions)

Two other independent third party testsuites found an extensive number of bugs and weaknesses in the SHA3 candidates. "Finding Bugs in Cryptographic Hash Function Implementations", Nicky Mouha, Mohammad S Raunak, D. Richard Kuhn, and Raghu Kacker, 2017. https://eprint.iacr.org/2017/891.pdf

Maybe independent researchers should come together to do a better public SHA-4 round, based on better and more testing methods, open source code for the tests, and using standard industry practices, such as valgrind, address-sanitizer and ubsan to detect obvious bugs.

PROBLEMS

Typical undefined behaviour (UB) problems: