PHP Hash Algorithm Benchmark
PHP supports a wide range of hashing functions, and from PHP 7.4, the Hash extension is bundled with PHP core.
Not all hash algorithms are equal. Among the list of hash algorithms included in PHP, it includes ones that have a lot of collisions, ones that are easy to break if used in cryptographic applications, and algorithms with various hash lengths.
PHP 8.1 adds support for MurmurHash3 and xxHash that are quite fast compared to other hashing algorithms including SHA3, MD5, and SHA2. In fact, the new xxh3
is the fastest hashing algorithm supported in PHP to date.
This benchmark was done on 100 MB of random data, with each hashing algorithm hashing the same random data blob, averaged from 5 runs, on an isolated Ubuntu 20.10 instance running on an AMD 4800H CPU, that has built-in CPU instructions for some hashing algorithms.
Algorithm name | Output width (bits) | Speed (GB/s) |
---|---|---|
xxh3 | 64 | 15.19 |
xxh128 | 128 | 14.78 |
crc32c | 32 | 14.12 |
xxh64 | 64 | 13.32 |
crc32 | 32 | 13.19 |
crc32b | 32 | 12.71 |
murmur3f | 128 | 8.87 |
xxh32 | 32 | 7.47 |
murmur3c | 128 | 6.20 |
murmur3a | 32 | 3.98 |
adler32 | 32 | 2.00 |
md4 | 128 | 1.12 |
fnv1a64 | 64 | 1.01 |
fnv132 | 32 | 1.00 |
fnv164 | 64 | 1.00 |
fnv1a32 | 32 | 0.98 |
joaat | 32 | 0.80 |
md5 | 128 | 0.77 |
tiger128,3 | 128 | 0.75 |
tiger160,3 | 160 | 0.75 |
tiger192,3 | 192 | 0.74 |
sha1 | 160 | 0.70 |
tiger160,4 | 160 | 0.57 |
tiger128,4 | 128 | 0.56 |
tiger192,4 | 192 | 0.56 |
ripemd128 | 128 | 0.49 |
ripemd256 | 256 | 0.46 |
sha3-224 | 224 | 0.43 |
sha3-256 | 256 | 0.41 |
sha384 | 384 | 0.38 |
sha512/224 | 224 | 0.38 |
sha512/256 | 256 | 0.38 |
sha512 | 512 | 0.38 |
ripemd320 | 320 | 0.33 |
ripemd160 | 160 | 0.32 |
sha3-384 | 384 | 0.31 |
haval128,3 | 128 | 0.30 |
haval160,3 | 160 | 0.30 |
haval192,3 | 192 | 0.30 |
haval224,3 | 224 | 0.30 |
haval256,3 | 256 | 0.30 |
sha224 | 224 | 0.25 |
sha256 | 256 | 0.25 |
sha3-512 | 512 | 0.22 |
haval128,4 | 128 | 0.22 |
haval160,4 | 160 | 0.22 |
haval192,4 | 192 | 0.22 |
haval224,4 | 224 | 0.22 |
haval256,4 | 256 | 0.22 |
haval128,5 | 128 | 0.17 |
haval160,5 | 160 | 0.17 |
haval192,5 | 192 | 0.17 |
haval224,5 | 224 | 0.17 |
haval256,5 | 256 | 0.17 |
whirlpool | 512 | 0.16 |
gost | 256 | 0.07 |
gost-crypto | 256 | 0.07 |
snefru | 256 | 0.03 |
snefru256 | 256 | 0.03 |
md2 | 128 | 0.01 |
The Output width (bits) column contains the number of bites the hashing algorithm produces. This is not necessarily the length when encoded. For example, when encoded to Hexadecimal, the output length will fourth of the Output width (bits) column value, because each hexadecimal character encodes four bits.