note 101669 deleted from function.hash by danbrown
| From: | danbrown@php.net | Date: | Mon, 03 Jan 2011 19:10:22 +0000 |
| Subject: | note 101669 deleted from function.hash by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175427@lists.php.net to get a copy of this message | ||
Note Submitter: alix dot axel at NOSPAM dot gmail dot com
----
I've benchmarked the speed of each algorithm, here are the results (in seconds) for 100 000
iterations using the PHP_VERSION constant as input:
md5 - 0.344965
md4 - 0.364629
sha1 - 0.394705
sha224 - 0.444182
adler32 - 0.977974
crc32 - 1.010282
crc32b - 1.073031
salsa20 - 1.195435
sha256 - 1.223975
salsa10 - 1.271891
tiger160,4 - 1.332259
tiger192,4 - 1.378207
tiger128,4 - 1.398811
tiger192,3 - 1.404048
haval192,3 - 1.407499
haval224,3 - 1.441333
tiger128,3 - 1.502407
haval128,3 - 1.512235
ripemd128 - 1.543352
haval256,4 - 1.555470
tiger160,3 - 1.570696
haval160,4 - 1.601446
ripemd256 - 1.604080
haval128,4 - 1.625974
haval224,4 - 1.634655
haval160,5 - 1.722719
ripemd320 - 1.734097
haval224,5 - 1.751882
haval160,3 - 1.771252
ripemd160 - 1.788433
haval256,5 - 1.812323
haval192,4 - 1.898074
haval128,5 - 1.915088
haval192,5 - 1.951288
haval256,3 - 2.139660
sha384 - 2.165917
snefru - 2.275385
whirlpool - 2.343090
snefru256 - 2.377666
gost - 2.420897
sha512 - 2.444197
md2 - 2.606721
Remember that when hashing sensitive information, (more) speed is not your friend; a slow hashing
algorithm will make the computation of rainbow tables slower.
Here is the source if you want to replicate this benchmark:
<?php
set_time_limit(0);
$result = array();
if (extension_loaded('hash') === true)
{
foreach (hash_algos() as $algorithm)
{
$result[$algorithm] = Benchmark('hash', array($algorithm, PHP_VERSION), 100000);
}
}
if (count($result) > 0)
{
asort($result);
}
echo '<pre>';
foreach ($result as $key => $value)
{
echo sprintf("%-10s\t- %8f\n", $key, $value);
}
echo '</pre>';
function Benchmark($function, $arguments = null, $iterations = 10000)
{
if (is_callable($function) === true)
{
$result = microtime(true);
for ($i = 1; $i <= $iterations; ++$i)
{
call_user_func_array($function, (array) $arguments);
}
return number_format(microtime(true) - $result, 8, '.', '');
}
return false;
}
?>