Created
October 21, 2018 05:43
-
-
Save kamermans/434e4611380d308790141d89a10c189e to your computer and use it in GitHub Desktop.
Compute the performance of every hashing function in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$loops = 100000; | |
$str = "whois foobar"; | |
$algos = hash_algos(); | |
$algo_padding = array_reduce($algos, function($carry, $val) { | |
$len = strlen($val); | |
if ($len > $carry) { | |
$carry = $len; | |
} | |
return $carry; | |
}); | |
$algo_padding++; | |
$timing = []; | |
$results = []; | |
foreach ($algos as $algo) { | |
$start = microtime(true); | |
for ($i=0; $i<$loops; $i++) { | |
$hash = hash($algo, $str); | |
} | |
$end = microtime(true); | |
$timing[$algo] = $end - $start; | |
$results[$algo] = [ | |
'ms' => (int)(($end - $start)*1000), | |
'hash' => $hash, | |
]; | |
} | |
asort($timing); | |
printf("%{$algo_padding}s %s %s\n", "Algo", "Time", "Hash"); | |
foreach ($timing as $algo => $time) { | |
$result = $results[$algo]; | |
printf("%{$algo_padding}s %s %s\n", $algo, $result['ms'], $result['hash']); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Algo Time Hash | |
fnv1a32 46 efe9fc54 | |
fnv132 47 4de89a4a | |
fnv164 47 546db3291906e94a | |
joaat 47 fc2e7567 | |
fnv1a64 47 a7cd31bace3e6bb4 | |
adler32 47 1f3c04c4 | |
crc32b 48 d36aa0b2 | |
crc32 48 894f3021 | |
md5 58 56cb649ea4b55cf63b9062a6b365ce5d | |
tiger128,3 63 20c35948e2b8c2e59744d31d5ffcc038 | |
tiger160,3 64 20c35948e2b8c2e59744d31d5ffcc03857755b50 | |
tiger192,3 65 20c35948e2b8c2e59744d31d5ffcc03857755b50b69ede67 | |
tiger128,4 66 7e43027ea2529cb3d7974c894e21c00d | |
sha1 67 13fd24cb4eb95903756ef6b92189856ef016f7bb | |
tiger192,4 69 7e43027ea2529cb3d7974c894e21c00d968e5e605ba4af2e | |
tiger160,4 71 7e43027ea2529cb3d7974c894e21c00d968e5e60 | |
md4 74 8579b96af30dc54306d99d7b2e5a8171 | |
ripemd128 77 a9907bcf59e30ffdc1a6bb65e13174c0 | |
ripemd256 82 4105acf6e1b3df516551a32d8b8f3061e9ff3bb9c31fec9e1d0bbf293da27803 | |
ripemd160 92 a213754ec3a174e57e1873a99f3b398d2cf9ce66 | |
sha224 93 9e90285716056b021d5f7072061cfe70b6332d99a35bb110a9734c44 | |
sha256 94 973661f8242bff90bd2d2aefe1433ecb558a06c493b46acb0e055f5e02e10d4b | |
ripemd320 96 daae4713db3aa3d7b8c92f2ee5e704e6cfdee113dbe2e1580d6a94fdb1bbbf32d75455286af1a935 | |
sha3-224 101 49687587b4315fac099648487e6f0fa1398e8b7e6256729d4372be9f | |
sha3-384 105 a30510533022f4d90860e3f837086c953155e50de50dee4e622e7c3b6acaec58d3f7675609eff7e068d8fda68395e0c6 | |
sha3-512 105 a4f779c84ea790e087af1c3740e6d730c8206cb6aa0ffe74f6e9604130a60a7952dd87cc7b829a4b9e9af53278d95dbd588597148c976af876c5f86ac39d6f8a | |
sha3-256 105 264d5472e558cb1c19f772700bf859fd9788794ef6cb1683b60814680d126605 | |
sha512/256 106 aa5c29d33e8ea7c67b0ec024ce1bc5ede0ef07e346ad718ca5e55614d3f31425 | |
sha512/224 106 a0f8f5bcb57f0924ab64f51ae35e92fd9b2477ad79b5f0d53424a261 | |
haval128,3 108 9793b3832916731cf0bb0271bdd10ed3 | |
whirlpool 108 01622476ecaa128aae1acbd9b984abbe25a4922fd50f84b78bf695da7cb2c78b42030ce5e72e84518f45c8d5a5d37a3903bdea07e4618c3854e230857b77234d | |
haval192,3 108 4d943da119bb284cc31b70bc438385c1cfd816609d6df141 | |
haval224,3 108 2bd65fb97be1d17bc546c04072789841c1ef74f1134369e6c8ed9587 | |
sha512 109 a019ca37eab2fb0966c612fda53bf02ec600b470ab84a29c6eac3101f8d27f4b777f17ccf908f72ad4d648c2533de7cfafb7d9a488190a5c33e1a29ed3d06502 | |
sha384 109 87b66d8a210e216a494baa8196dd355923c7d98ab3a059e27bad251dc62831880994bffec1114739d3df22714476fdcf | |
haval160,3 109 08a1347435baea3dbaba3361ce8fd93c4469dcce | |
haval256,3 111 2701615e80a63c07a3e469d3a8abd8b4f6a7e2fbbcef0819af70ed9be3b935f1 | |
haval160,4 129 45428cbd4f0b41cfcb3efa141a8259436d47ca51 | |
haval128,4 129 e53d37b7d9f2896937413aecf6e25567 | |
haval224,4 130 8a34ef0ccf7fd4d4eaaa5261752d191ed895c4187a0d16b957f64e40 | |
haval192,4 130 ffe7e9c05583c0d0f96bad9aabe28eabbf0a0bcd0b87b1f4 | |
haval256,4 135 0bde2a7dc17a02ca0461e9d763b5025a754cac87f573dce57c5aa630aab2aef5 | |
haval160,5 147 5cd750dffb5803a3e740ba657f0a3331f03318f0 | |
haval128,5 148 807294498239287b7c8ddbdbc57200db | |
haval256,5 148 ba90285f6161bf5fce4994169e9a0fec50c75b81a4ea4afc763d37a6cdf427b8 | |
haval224,5 148 b9e55c7821106f1baefdfd0a1c54efc7c95af2d08b5d41f7a4416a82 | |
haval192,5 150 f32a0d259b57add7456be680d3e6cfa61ceb8beb934d655c | |
gost 210 9a3ddd294e14f1dd5c79ff68be7370785fc8f83b0a3e069cc44a34e171cc1e62 | |
gost-crypto 215 27f4f0fd2c6cceb5512bc2d820e6169a340e5eb98c05214de803157d00e65008 | |
snefru 276 8674db1165f6feb3e5569695360d872865b12a87f767d01fa4d59ac5424efe29 | |
snefru256 277 8674db1165f6feb3e5569695360d872865b12a87f767d01fa4d59ac5424efe29 | |
md2 479 157d1c4e0d217d989df5b78e9b70f1d7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment