Created
January 8, 2011 21:22
-
-
Save snichme/771164 to your computer and use it in GitHub Desktop.
Simple script for listing the different hash algorithms installed on your system
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
<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