PHP Hash Algorithm Benchmark

Published On2020-11-20

PHP Hash 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 are has 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, that is quite fast compared to other hashing algorithms including SHA3, MD5, and SHA2.

This benchmark was done on PHP master branch builds on an x64 system, and averaged results from 5 runs. For each run, the hash function was called with each hashing algorithm 1 million times on a 5 fixed inputs ranging from 5 bytes to 256 bytes. Note that the absolute numbers can be different from one system to another, but major relative differences should remain the same.


Algorithm name Duration for 1 million iterations (seconds) Output hash length (bytes)
md2 5.365084887 16
md4 0.269670963 16
md5 0.274549007 16
sha1 0.397055864 20
sha224 0.710157156 28
sha256 0.744663954 32
sha384 0.953479052 48
sha512/224 0.955487013 28
sha512/256 0.98586297 32
sha512 0.997375965 64
sha3-224 0.855549097 28
sha3-256 0.892877102 32
sha3-384 0.910125017 48
sha3-512 0.932621956 64
ripemd128 0.514116049 16
ripemd160 0.661270857 20
ripemd256 0.549931049 32
ripemd320 0.693521023 40
whirlpool 0.927204132 64
tiger128,3 0.293726206 16
tiger160,3 0.322802067 20
tiger192,3 0.333410025 24
tiger128,4 0.361637831 16
tiger160,4 0.360008001 20
tiger192,4 0.384588003 24
snefru 3.180413961 32
snefru256 3.19028306 32
gost 2.277826071 32
gost-crypto 2.365000963 32
adler32 0.128689051 4
crc32 0.139811993 4
crc32b 0.128334045 4
crc32c 0.150944948 4
fnv132 0.126981974 4
fnv1a32 0.135647774 4
fnv164 0.118499041 8
fnv1a64 0.140213013 8
joaat 0.137438774 4
murmur3a 0.132889032 4
murmur3c 0.160674095 16
murmur3f 0.149187088 16
haval128,3 0.978699923 16
haval160,3 0.944957972 20
haval192,3 0.960014105 24
haval224,3 0.961600065 28
haval256,3 0.961845875 32
haval128,4 1.214588881 16
haval160,4 1.823944807 20
haval192,4 2.087178946 24
haval224,4 1.366857052 28
haval256,4 1.281467915 32
haval128,5 1.455754995 16
haval160,5 1.632586002 20
haval192,5 1.992477894 24
haval224,5 1.466537952 28
haval256,5 1.555293083 32

The Output hash length (bytes) fields indicates how many bytes each hash function returns. hash function formats the output to Hexadecimal (base 16, with 0-9 and a-f) by default. Each Hexadecimal character (Hextet) holds 0.5 bytes of data and thus if the hash output is formatted to Hexadecimal, the output string length will be twice the value of Output hash length (bytes) column.

Hash Benchmark

PHP Hash Benchmark - Chart

Recent Articles on PHP.Watch

All Articles β€’ Feed
PHP 8.0 Thanks ❀

PHP 8.0 Thanks ❀

PHP 8.0.0 is released today πŸŽ‰πŸΎπŸŽŠ. Thank you all of you for your amazing efforts ❀.
PHP's resource to object transformation

PHP's resource to object transformation

A summary of PHP's long-term progress in `resource` objects to class objects
Xdebug 2 vs Xdebug 3 Performance Comparison

Xdebug 2 vs Xdebug 3 Performance Comparison

A performance comparison between Xdebug 2 and the upcoming version 3.
Subscribe to PHP.Watch newsletter for monthly updates

You will receive an email on last Saturday of every month and on major PHP releases with new articles related to PHP, upcoming changes, new features and what's changing in the language. No marketing emails, no selling of your contacts, no click-tracking, and one-click instant unsubscribe from any email you receive.