protected function report()
{
// all report data: keyed by row, then by col
$report = array();
// keep track of the comparison bench average
$cmp = 9999999999;
// number formatting
$format = '%8.2f';
// padding for the target name column
$name_pad = 8;
// each of the targets benched
foreach ($this->req_sec as $name => $concs) {
// keep a padding for the longest name
$len = strlen($name);
if ($len > $name_pad) {
$name_pad = $len;
}
// each of the concurrency levels for the target
foreach ($concs as $conc => $passes) {
// output the bench on its own line
$report[$name][$conc] = array('rel' => null, 'avg' => null);
// read the pass data
foreach ($passes as $pass => $req_sec) {
$report[$name][$conc][$pass] = sprintf($format, $req_sec);
}
// figure the average
$numer = array_sum($report[$name][$conc]);
$denom = (count($report[$name][$conc]) - 2); // -2 for rel, avg
$avg = $numer / $denom;
$report[$name][$conc]['avg'] = sprintf($format, $avg);
// if this is the comparison target, save the comparison value
if ($name == $this->compare) {
$cmp = $avg;
}
}
}
// always add some extra name padding
$name_pad += 2;
// header line
$this->outln();
$this->out(str_pad('Target', $name_pad));
$this->out(' | concurr');
$this->out(' | relative');
$this->out(' | average');
for($i = 1; $i <= $this->passes; $i++) {
$this->out(' | ' . str_pad($i, 8, ' ', STR_PAD_LEFT));
}
$this->outln();
// separator line
$this->out(str_pad('', $name_pad, '-'));
for ($i = 1; $i <= $this->passes + 3; $i++) {
$this->out(' | --------');
}
$this->outln();
// go through each reported target ...
foreach ($report as $name => $concs) {
// for each concurrency level ...
foreach ($concs as $conc => $data) {
// compute the relative performance as we go
if ($this->compare) {
$data['rel'] = sprintf("%8.4f", $data['avg'] / $cmp);
} else {
$data['rel'] = ' n/a ';
}
// the target name
$this->out(str_pad($name, $name_pad) . " | ");
// the concurrency level
$this->out(sprintf("%8d", $conc) . " | ");
// relative, average, and passes
$this->outln(implode(" | ", $data));
}
}
}