Skip to content

Instantly share code, notes, and snippets.

@OO00O0O
Last active August 19, 2025 09:36
Show Gist options
  • Select an option

  • Save OO00O0O/27ae1b5b70b4982455ea57b623c13aba to your computer and use it in GitHub Desktop.

Select an option

Save OO00O0O/27ae1b5b70b4982455ea57b623c13aba to your computer and use it in GitHub Desktop.
Bench PHP hash algorithms speeds
<?php declare(strict_types=1);
echo "PHP Version: " . PHP_VERSION . "\n";
$times = [];
foreach(hash_algos() as $algorithm) {
$times[$algorithm] = 0.0;
}
for($i = 0; $i < 100_000; $i++) {
$string = preg_replace_callback('/A/', fn () => '0123456789abcdefghijklmnopqrstuvwxyz'[mt_rand(0, 35)], str_repeat('A', 500));
foreach($times as $algorithm => &$time) {
$start = microtime(true);
hash($algorithm, $string);
$time += microtime(true) - $start;
}
}
asort($times);
echo str_pad("Algorithm", 16) . "Time(ms)\n";
foreach($times as $algorithm => $time) {
echo str_pad($algorithm, 16) . round($time * 1000, 2) . "\n";
}
@OO00O0O
Copy link
Author

OO00O0O commented Aug 19, 2025

MacBook M4 Pro(2024) MacOS 15.6 (24G84)

PHP Version: 8.4.10
Algorithm       Time(ms)
xxh64           19.77
xxh32           21.2
xxh3            22.46
xxh128          22.57
murmur3f        25.13
murmur3c        25.87
murmur3a        31.75
adler32         41.39
md4             57.55
fnv1a64         62.18
fnv164          62.42
fnv132          62.48
fnv1a32         62.5
sha1            66.01
tiger192,3      71.58
tiger160,3      71.78
joaat           74.41
md5             76.43
tiger128,3      77.86
sha3-256        85.31
sha3-224        87.51
tiger192,4      88.63
tiger160,4      88.81
tiger128,4      88.88
sha3-384        101.23
crc32c          103.36
crc32b          104.01
crc32           105.21
ripemd128       110.3
ripemd256       111.78
sha512/224      122.6
sha512/256      123.02
sha512          123.56
sha384          124.48
haval192,3      126.63
haval160,3      126.76
haval256,3      127.38
haval224,3      128.3
haval128,3      130.59
sha3-512        133.09
sha256          139.16
sha224          140.39
ripemd320       145.16
ripemd160       146.47
whirlpool       168.89
haval192,4      172.94
haval160,4      173.03
haval256,4      173.67
haval224,4      174.23
haval128,4      179.31
haval256,5      179.31
haval192,5      209.11
haval224,5      209.26
haval160,5      210.11
haval128,5      215.51
gost-crypto     547.46
gost            549.88
snefru256       1364.34
snefru          1382.12
md2             4279.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment