Skip to content

Instantly share code, notes, and snippets.

@alexpott
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpott/202a520d3bec69a8d1d6 to your computer and use it in GitHub Desktop.
Save alexpott/202a520d3bec69a8d1d6 to your computer and use it in GitHub Desktop.
<?php
function quantile($values, $p) {
sort($values);
$H = (count($values) - 1) * $p + 1;
$h = floor($H);
$v = $values[$h - 1];
$e = $H - $h;
return $e ? $v + $e * ($values[$h] - $v) : $v;
}
function sumarize($values) {
$output = array();
$output['min'] = number_format(min($values), 4);
$output['max'] = number_format(max($values), 4);
$output['mean'] = number_format(array_sum($values) / count($values), 4);
$output['median'] = number_format(quantile($values, 0.5), 4);
$output['95th'] = number_format(quantile($values, 0.95), 4);
return $output;
}
$file_list = shell_exec('find core| grep -v vendor | grep \.yml$');
$files = array_filter(explode("\n", $file_list));
$md5_times = array();
$sha_times = array();
foreach ($files as $file) {
$string = file_get_contents($file);
$start = microtime(TRUE);
md5($string);
$md5_times[] = (microtime(TRUE) - $start) * 1000;
$start = microtime(TRUE);
hash('sha512', $string);
$sha_times[] = (microtime(TRUE) - $start) * 1000;
}
print_r(sumarize($md5_times));
print_r(sumarize($sha_times));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment