SMhasher

Alternative timings with an old but stable Intel i5-2300 2.8GHz desktop PC on 32bit:

Hash function MiB/sec cycl./hash cycl./map size Quality problems
donothing32 21848741.94 5.00 - 13 test NOP
donothing64 22420895.07 5.00 - 13 test NOP
donothing128 22158744.05 5.00 - 13 test NOP
NOP_OAAT_read64 20215704.01 20.00 - 47 test NOP
BadHash 754.44 82.74 - 47 test FAIL
sumhash 11217.99 34.71 - 363 test FAIL
sumhash32 43651.41 33.51 - 863 UB, test FAIL

crc32 385.18 140.80 212.42 (7) 422 insecure, 8590x collisions, distrib
md5_32 430.99 525.23 786.38 (6) 4419 8590x collisions, distrib
md5_64 432.28 531.04 798.35 (9) 4419
sha1_32 477.30 830.46 1123.82 (8) 5126 collisions, 36.6% distrib
sha1_64 499.94 826.55 1140.50 (6) ?
md5-128 437.91 556.62 816.02 (7) 4419
sha1-160 490.91 898.33 1180.24 (5) 5126 Comb/Cyclic low32
sha2-224 152.76 1317.99 1559.05 (8) Cyclic low32
sha2-224_64 150.65 1311.95 1552.11 (6) Cyclic low32
sha2-256 153.81 1303.78 1523.35 (7)
sha2-256_64 151.48 1313.42 1539.60 (20)
blake3_c 731.64 407.77 624.46 (7) Moment Chi2, no 32bit portability
rmd128 290.34 711.71 922.92 (6)
rmd160 184.85 1070.69 1292.47 (11)
rmd256 335.72 638.50 853.75 (8)
edonr224 589.93 441.90 655.12 (2)
edonr256 578.61 451.13 664.69 (5)
blake2s-128 295.78 781.82 1000.64 (5)
blake2s-160 293.87 792.83 996.13 (8)
blake2s-224 294.40 794.36 1020.84 (6)
blake2s-256 299.61 794.92 1026.98 (5)
blake2s-256_64 292.07 793.36 1025.47 (6)
blake2b-160 83.37 4917.75 5144.02 (10)
blake2b-224 66.32 5871.55 6079.06 (12)
blake2b-256 66.26 5913.02 6105.54 (15) Sparse high 32-bit
blake2b-256_64 66.06 6124.16 6666.31 (10)
asconhashv12 29.66 4285.27 3775.21 (4)
asconhashv12_64 30.30 1931.66 1415.42 (7)
sha3-256 37.33 11027.50 - PerlinNoise
sha3-256_64 37.82 10224.27 - PerlinNoise
hasshe2 2832.38 68.97 214.95 (3) 445 Permutation,TwoBytes,Zeroes,Seed
tabulation32 5570.15 65.46 212.25 (3) 848 collisions
crc32_hw 3062.40 53.19 177.88 (2) 653 insecure, 100% bias, collisions, distrib, machine-specific (x86 SSE4.2)
crc32_hw1 23208.73 46.74 179.70 (2) 671 insecure, 100% bias, collisions, distrib, machine-specific (x86 SSE4.2)
crc64_hw 3100.68 54.70 179.01 (2) 652 insecure, 100% bias, collisions, distrib, machine-specific (x64 SSE4.2)
crc32_pclmul 1972140.38 7.00 - 481 insecure, 100% bias, collisions, distrib, machine-specific (x86 PCLMUL)
crc64_jones1 899.65 151.71 248.72 (2) insecure, 100% bias, collisions, distrib, machine-specific
crc64_jones2 1559.02 197.47 265.21 (4) insecure, 100% bias, collisions, distrib, machine-specific
crc64_jones3 1763.43 208.18 285.74 (6) insecure, 100% bias, collisions, distrib, machine-specific
crc64_jones 1767.82 152.42 242.14 (4) insecure, 100% bias, collisions, distrib, machine-specific
o1hash 20761605.46 24.40 181.46 (3) 101 insecure, zeros, fails all tests
fibonacci 24267.30 33.89 186.07 (2) 1692 UB, zeros, fails all tests
FNV1a 773.65 80.14 188.28 (3) 204 zeros, fails all tests
FNV1A_Totenschiff 4970.78 42.92 195.06 (4) 270 UB, zeros, fails all tests
FNV1A_Pippip_Yurii 3059.45 54.56 200.96 (3) 147 UB, sanity, fails all tests
FNV1a_YT 14707.39 36.82 172.52 (3) 321 UB, fails all tests
FNV2 3114.57 38.69 179.97 (3) 278 fails all tests
FNV64 255.57 229.81 263.83 (5) 79 fails all tests
FNV128 91.54 540.82 734.13 (3) 171 fails all tests
k-hash32 2151.05 61.71 205.41 (4) 808 UB, insecure, zeros, fails all tests
k-hash64 2401.55 102.79 269.99 (2) 609 UB, insecure, zeros, fails all tests
fletcher2 22885.47 32.50 350.04 (2) 248 UB, fails all tests
fletcher4 23193.95 32.44 348.12 (1) 371 UB, fails all tests
bernstein 1027.82 64.92 185.13 (3) 41 fails all tests
sdbm 765.22 78.18 185.97 (3) 41 fails all tests
x17 770.42 81.69 189.46 (2) 79 99.98% bias, fails all tests
libiberty 619.89 92.75 188.11 (3) 37 insecure, 100% bias, fails all tests
gcc 614.42 93.82 189.39 (2) 39 insecure, 100% bias, fails all tests
JenkinsOOAT 611.86 122.15 220.57 (4) 153 53.5% bias, fails all tests
JenkinsOOAT_perl 616.14 101.36 198.85 (2) 65 1.5-11.5% bias, 7.2x collisions, LongNeighbors
MicroOAAT 730.72 84.38 193.79 (3) 68 100% bias, distrib
beamsplitter 85.55 2510.43 2586.71 (6) UB, too many bad seeds,
VHASH_32 1400.08 179.75 404.87 (5) 1231 sanity, Seed, MomentChi2
VHASH_64 1405.03 182.42 447.87 (34) 1231 sanity, Seed, Sparse
farsh32 23162.21 129.30 307.12 (2) 944 insecure: AppendedZeroes, collisions+bias, MomentChi2, LongNeighbors
farsh64 11586.38 235.59 408.91 (4) 944 insecure: AppendedZeroes, collisions+bias, MomentChi2, LongNeighbors
farsh128 5594.27 480.66 684.23 (10) ??
farsh256 2907.80 925.56 1122.54 (6) ??
jodyhash32 1776.46 49.08 186.55 (3) 102 bias, collisions, distr, 1 bad seed, LongNeighbors
jodyhash64 1040.32 77.74 213.34 (2) 118 bias, collisions, distr, LongNeighbors
lookup3 2429.59 46.84 191.53 (3) 341 UB, 28% bias, collisions, 30% distr
superfast 2055.40 57.13 185.67 (2) 210 UB, 91% bias, 5273.01x collisions, 37% distr, BIC
MurmurOAAT 509.78 111.95 198.21 (2) 47 collisions, 99.998% distr., BIC, LongNeighbors
Crap8 2905.11 55.06 195.54 (1) 342 UB, 2.42% bias, collisions, 2% distrib
Murmur1 2057.34 55.05 177.13 (2) UB, fails all tests, 1 bad seed
Murmur2 3081.86 48.22 180.20 (2) 358 UB, 1.7% bias, 81x coll, 1.7% distrib, BIC
Murmur2A 3103.96 52.50 194.11 (2) 407 UB, 12.7% bias, LongNeighbors
Murmur2B 4882.95 39.72 149.43 (2) 433 UB, 1.8% bias, collisions, 3.4% distrib, BIC
Murmur2C 3778.68 58.83 197.63 (3) 444 UB, 91% bias, collisions, distr, BIC, LongNeighbors
Murmur3A 2978.62 54.60 192.85 (2) 351 UB, Moment Chi2 69
PMurHash32 2981.24 54.98 190.94 (3) 1862 Moment Chi2 69
Murmur3C 4755.20 63.36 224.77 (4) 859 UB, LongNeighbors, DiffDist
PMPML_32 5865.18 53.31 192.07 (2) 1084 Avalanche >512, unseeded: Seed, MomentChi2
PMPML_64 8161.19 53.20 179.16 (2) 1305 unseeded: Seed, MomentChi2
xxHash32 5607.81 55.30 202.20 (3) 738 LongNeighbors, collisions with 4bit diff, MomentChi2 220
metrohash64_1 2839.69 107.56 220.17 (2) 624 UB, LongNeighbors, BIC, MomentChi2
metrohash64_2 2792.18 109.08 228.56 (2) 627 UB, LongNeighbors
metrohash64crc_1 14000.50 49.08 150.54 (2) 632 UB, cyclic collisions 8 byte, BIC, MomentChi2, machine-specific (x64 SSE4.2)
metrohash64crc_2 14034.84 48.94 162.54 (2) 632 UB, cyclic collisions 8 byte, BIC, machine-specific (x64 SSE4.2)
metrohash128_1 2946.24 206.81 337.22 (6) 773 UB, LongNeighbors
metrohash128_2 2945.29 207.67 326.83 (4) 773 UB, LongNeighbors
cmetrohash64_1o 9658.31 42.84 163.45 (1) 3506 LongNeighbors, MomentChi2
cmetrohash64_1 9683.33 45.20 161.01 (2) 652 LongNeighbors, BIC, MomentChi2
cmetrohash64_2 9669.95 44.75 149.67 (2) 655 LongNeighbors
City64noSeed 2598.52 68.01 219.01 (4) 1038 Avalanche, Sparse, TwoBytes, MomentChi2, Seed
City64 2576.48 97.39 254.44 (4) 1120 Sparse, TwoBytes
t1ha1_64be 2291.15 131.41 267.58 (3) 555 Avalanche
t1ha0_32le 3928.60 67.73 216.56 (12) 509 Sparse, LongNeighbors
t1ha0_32be 3863.31 69.64 204.92 (2) 533 Sparse, LongNeighbors
t1ha2_stream 2525.02 276.72 453.03 (4) 1665 Sparse, Permutation, LongNeighbors
t1ha2_stream128 2523.58 355.00 544.07 (3) 1665 Sparse, Permutation, LongNeighbors
aesnihash 5517.48 91.51 245.96 (3) 1209 fails many tests, machine-specific (x64 AES-NI)
falkhash 20202.42 173.63 321.52 (2) 264 Sparse, LongNeighbors, machine-specific (x64 AES-NI)
MeowHash 17371.91 85.48 247.96 (2) 1764 Sparse, machine-specific (x64 AES-NI)
MeowHash64low 17378.06 85.48 237.60 (2) 1764 Sparse, machine-specific (x64 AES-NI)
MeowHash32low 17374.64 85.48 258.53 (2) 1764 Sparse, machine-specific (x64 AES-NI)
t1ha1_64le 2581.55 128.61 264.69 (2) 517 Avalanche
tifuhash_64 132.13 915.25 861.62 (6) 276
floppsyhash 133.26 1057.42 - 623
chaskey 1140.11 130.78 288.36 (2) 1609 PerlinNoise
SipHash 937.65 176.53 317.19 (8) 1071
HalfSipHash 1128.62 91.72 218.10 (2) 700 zeroes
GoodOAAT 735.47 94.07 201.91 (3) 237
pearsonbhash64 587.53 265.27 364.86 (3) 683
pearsonbhash128 431.77 367.91 453.50 (4) 1134
pearsonbhash256 488.65 374.41 473.18 (5) 844
prvhash64_64m 762.79 149.78 275.87 (3) 349
prvhash64_64 763.33 149.89 291.37 (3) 384
prvhash64_128 899.28 216.27 361.06 (2) 718
prvhash64s_64 1973.06 891.32 1120.71 (12) 2640
prvhash64s_128 2002.64 1243.71 1502.62 (12) 2799
SipHash13 1845.54 130.51 281.22 (3) 778 0.9% bias
TSip 799.14 181.14 311.57 (4) 519 !msvc
discohash1 840.44 683.63 809.35 (6) 1294
discohash1-128 818.81 894.40 1007.31 (7) 1294
discohash2 832.28 686.14 817.42 (6) 1294
discohash2-128 739.13 892.89 1011.30 (7) 1294
discoNONG 863.56 1692.78 - (too slow) bad seeds
aesni 31185.98 29.45 226.75 (2) 519 machine-specific (x64 AES-NI)
aesni-low 28020.87 36.75 209.22 (3) 519 machine-specific (x64 AES-NI)
seahash 1879.42 123.65 297.80 (4) 871 PerlinNoise, !msvc
seahash32low 1878.84 120.28 303.16 (4) 871 PerlinNoise, !msvc
clhash 4472.31 82.72 229.73 (3) 1809 PerlinNoise, machine-specific (x64 SSE4.2)
HighwayHash64 6242.58 99.55 248.41 (3) 2546
Murmur3F 5226.40 52.18 175.85 (1) 699 UB
fasthash32 2772.36 89.78 241.92 (4) 566 UB
fasthash64 2733.24 92.44 243.89 (2) 509 UB, Moment Chi2 5159 !
MUM 1260.69 123.19 289.94 (2) 1912 UB, too many bad seeds, machine-specific (32/64 differs)
MUMlow 1275.57 123.12 288.82 (3) 1912 UB, 5 bad seeds
xmsx32 1361.63 70.68 207.63 (3) 288 2 bad seeds
mirhash 1341.67 109.36 235.44 (2) 1112 2^36 bad seeds, UB, LongNeighbors, machine-specific (32/64 differs)
mirhash32low 1341.65 113.35 244.59 (3) 1112 4 bad seeds, UB, Cyclic, LongNeighbors, machine-specific (32/64 differs)
mirhashstrict 1319.02 111.04 240.90 (2) 1112
mirhashstrict32low 1330.23 115.14 244.09 (3) 1112 1 bad seed, MomentChi2 9
mx3 2173.61 118.71 256.70 (2) 734 UB
pengyhash 1552.08 262.17 500.96 (40) 421
City32 5721.29 60.55 203.02 (4) 1319
City64low 2587.16 95.61 247.26 (3) 1120
City128 9640.19 88.45 225.38 (3) 1841
CityCrc128 12343.43 74.50 209.75 (2) 295
CityCrc256 19603.25 42.27 149.40 (4)
FarmHash32 16500.11 58.38 212.49 (3) 11489 machine-specific (x64 SSE4/AVX)
FarmHash64 2587.74 109.20 257.44 (4) 3758
FarmHash128 1852.38 202.43 337.92 (4) 163
farmhash32_c 16299.81 47.79 219.19 (4) 762 machine-specific (x64 SSE4/AVX)
farmhash64_c 8713.16 47.96 201.00 (2) 3688
farmhash128_c 9244.13 79.08 209.44 (2) 1890
metrohash64 2786.43 108.86 234.48 (4) 624 LongNeighbors
metrohash128 2946.29 207.27 328.88 (5) 624 UB
metrohash128crc_1 13948.67 65.20 168.08 (2) 723 UB, machine-specific (x64 SSE4.2)
metrohash128crc_2 13920.19 65.12 176.70 (1) 723 UB, machine-specific (x64 SSE4.2)
xxHash64 1904.23 141.49 248.45 (4) 1999
Spooky32 2168.78 229.37 355.64 (4) 2221 UB
Spooky64 2162.34 269.13 398.42 (5) 2221 UB
Spooky128 2212.10 264.56 398.39 (4) 2221 UB
SpookyV2_32 2206.46 228.41 359.23 (3) 2069
SpookyV2_64 2192.78 271.80 406.67 (6) 2069
SpookyV2_128 2205.11 268.57 390.10 (4) 2069
t1ha2_atonce 2826.99 140.18 272.05 (4) 541
t1ha2_atonce128 2864.56 282.61 406.85 (4) 613 LongNeighbors
t1ha0_aes_noavx 27726.49 138.67 274.00 (3) 925 LongNeighbors, machine-specific (x86 AES-NI)
t1ha0_aes_avx1 27679.90 142.78 278.43 (3) 843 LongNeighbors, machine-specific (x64 AVX)
t1ha0_aes_avx2 55489.36 140.83 276.39 (3) 792 LongNeighbors, machine-specific (x64 AVX2)
xxh3 20350.90 105.84 234.71 (4) 744 Moment Chi2 14974, BIC
xxh3low 20585.46 100.56 227.58 (3) 756 Moment Chi2 1.8e+9 !
xxh128 18818.43 129.14 255.43 (2) 1012 Moment Chi2 14974
xxh128low 19088.33 122.14 252.07 (3) 1012 Moment Chi2 14974, BIC
MeowHash 17371.91 85.48 247.96 (2) 1764 Sparse low32, machine-specific (x64 AES-NI)
MeowHash32low 17374.64 85.48 258.53 (2) 1764 Sparse, machine-specific (x64 AES-NI)
wyhash 1736.80 111.32 235.21 (1) 474
wyhash32 1864.46 63.82 206.87 (5) 426 4 bad and broken seeds, 32-bit
wyhash32low 12194.76 26.83 182.34 (1) 474 5 bad seeds
rapidhash 2304.23 120.47 254.63 (4) 574
rapidhash_unrolled 2160.44 118.58 251.86 (4) 782
umash32 4633.19 53.42 216.33 (3) 1530
umash32_hi 4662.92 54.22 214.20 (2) 1530
umash64 4662.09 53.42 188.09 (1) 1530
umash128 2427.46 70.60 197.29 (2) 1530
halftime_hash64 2595.67 156.65 335.59 (4) 1530
halftime_hash128 14910.90 186.68 378.10 (4) 1530
halftime_hash256 15565.75 185.44 412.00 (4) 1530
halftime_hash512 9146.98 311.00 518.86 (6) 1530
nmhash32 9061.54 63.07 215.21 (6) 2445
nmhash32x 9209.11 49.68 193.06 (4) 1494
komihash 1972.48 134.48 266.88 (3) 2799
polymur 1019.23 168.67 304.50 (4) 1128
gxhash32 44875.37 43.49 218.40 (4) 736 AES only
gxhash64 46810.04 43.86 204.13 (2) 720 AES only
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: