Skip to content

Instantly share code, notes, and snippets.

@mwgamera
Created October 27, 2012 18:08
Show Gist options
  • Save mwgamera/3965548 to your computer and use it in GitHub Desktop.
Save mwgamera/3965548 to your computer and use it in GitHub Desktop.
<?php
$SIZE = 4987;
$data = array();
$seed = array();
for ($i = 0; $i < $SIZE; $i++) {
$data[] = hash('sha512', microtime().$i.@$seed[$i-1], true);
$seed[] = hash('sha224', microtime().$i.@$data[$i-1], true);
}
foreach (hash_algos() as $algo) {
hash_hmac($algo, '', '');
do {
$n = 0;
$m = 0;
$M = 0;
for ($i = 0; $i < $SIZE; $i++) {
$t0 = microtime();
hash_hmac($algo, $data[$i], $seed[$i]);
$t1 = microtime();
$t0 = explode(' ', $t0);
$t1 = explode(' ', $t1);
$t0 = $t0[1] . substr($t0[0], 1);
$t1 = $t1[1] . substr($t1[0], 1);
$x = bcmul(bcsub($t1, $t0, 6), 1000000);
$d = $x - $m;
$m += $d / ++$n;
$M += $d * ($x - $m);
}
$s = sqrt($M / ($n-1));
printf("\r(%9.5f ± %9.5f) µs %s\033[K", $m, $s, $algo);
} while ($s/$m >= 0.15 && $n < 79*$SIZE);
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment