Skip to content

Instantly share code, notes, and snippets.

@msonnabaum
Created February 27, 2013 23:36
Show Gist options
  • Save msonnabaum/5052884 to your computer and use it in GitHub Desktop.
Save msonnabaum/5052884 to your computer and use it in GitHub Desktop.
<?php
require './core/vendor/autoload.php';
use Symfony\Component\Yaml\Parser;
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));
$extension_times = array();
$symfony_times = array();
foreach ($files as $file) {
$start = microtime(TRUE);
$extension = yaml_parse_file($file);
$extension_times[] = (microtime(TRUE) - $start) * 1000;
$parser = new Parser();
$start = microtime(TRUE);
$symfony = $parser->parse(file_get_contents($file));
$symfony_times[] = (microtime(TRUE) - $start) * 1000;
}
print yaml_emit(array('extension' => sumarize($extension_times)));
print yaml_emit(array('symfony' => sumarize($symfony_times)));
@sun
Copy link

sun commented Feb 22, 2014

Nice one :) I'll try to merge the summary() + quantile() functions into my bench.php script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment