Guest User

Untitled

a guest
Jul 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. <pre>
  2. <?php
  3.  
  4. function microtime_float() {
  5. list($usec, $sec) = explode(" ", microtime());
  6. return ((float)$usec + (float)$sec);
  7. }
  8. $algos = hash_algos();
  9. $string = "The quick brown fox jumped over the lazy dog.";
  10.  
  11.  
  12. echo "Prints out hash of the string \"".$string."\"\nusing the different algorithms you have installed in your PHP setup.\n";
  13. echo "It runs the hash function 1000 times and calculates the mean value of the execution time.\n";
  14. echo "The execution time is presented in milliseconds\n\n";
  15.  
  16. foreach($algos as $algo) {
  17.  
  18. echo $algo . "\n";
  19. echo hash($algo, $string) . "\n";
  20. $res_time = 0;
  21. for($i = 0; $i < 1000;$i++) {
  22. $time_start = microtime_float();
  23. hash($algo, $string);
  24. $res_time += microtime_float() - $time_start;
  25. }
  26.  
  27. echo "Executed in " . round($res_time*1000, 3) . " milliseconds\n";
  28. echo "\n\n";
  29. }
  30. ?>
  31. </pre>
Add Comment
Please, Sign In to add comment