Skip to content

Instantly share code, notes, and snippets.

@snichme
Created January 8, 2011 21:22
Show Gist options
  • Save snichme/771164 to your computer and use it in GitHub Desktop.
Save snichme/771164 to your computer and use it in GitHub Desktop.
Simple script for listing the different hash algorithms installed on your system
<pre>
<?php
function microtime_float() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$algos = hash_algos();
$string = "The quick brown fox jumped over the lazy dog.";
echo "Prints out hash of the string \"".$string."\"\nusing the different algorithms you have installed in your PHP setup.\n";
echo "It runs the hash function 1000 times and calculates the mean value of the execution time.\n";
echo "The execution time is presented in milliseconds\n\n";
foreach($algos as $algo) {
echo $algo . "\n";
echo hash($algo, $string) . "\n";
$res_time = 0;
for($i = 0; $i < 1000;$i++) {
$time_start = microtime_float();
hash($algo, $string);
$res_time += microtime_float() - $time_start;
}
echo "Executed in " . round($res_time*1000, 3) . " milliseconds\n";
echo "\n\n";
}
?>
</pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment