Voting

: zero plus three?
(Example: nine)

The Note You're Voting On

jrz [dot] agarcia [at] gmail [dot] com
8 years ago
I was curious about hashes behavior (time and length), so i ran this code (yeah, I'm cheating because i took two examples from this page)
<?php
 echo "Building data...";
 $data = "";
 for($i = 0; $i < 1500; $i++)
 $data .= sha1("H:k - $i - k:H");
 echo "OK! (".strlen($data)." bytes)".PHP_EOL;
 $res = [];
 echo "Testing hashes.....".PHP_EOL;
 foreach (hash_algos() as $algo) {
 $time = microtime(1);
 $hash = hash($algo, $data);
 $time = (microtime(1) - $time) * 1000;
 $length = strlen($hash);
 $res["$time"][] = [
 "algo" => "HEX-$algo",
 "length" => "$length",
 "time" => sprintf("%.8f", $time)
 ];
 $time = microtime(1);
 hash($algo, $data, 1);
 $time = (microtime(1) - $time) * 1000;
 $res["$time"][] = [
 "algo" => "RAW-$algo",
 "length" => "$length",
 "time" => sprintf("%.8f", $time)
 ];
 }
 ksort($res);
 $i = 0;
 echo "Results:".PHP_EOL;
 echo "Posit. Time in ms Type-Hash algo Hash length".PHP_EOL;
 foreach($res as $sres){
 foreach($sres as $result){
 echo sprintf("%5d. %12s ms %-20s %-2d bytes", $i++, $result['time'], $result['algo'], $result['length']).PHP_EOL;
 }
 }
?>

I found interesting that today (may 31, 2018), I found 103 algos, 65 more than 9 years ago (based on this comment: https://secure.php.net/manual/en/function.hash.php#89574 )
Also, here is my results: https://ideone.com/embed/0iwuGn
I'm not posting here due to message length limitations.

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /