forked from fabpot-graveyard/framework-benchs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.php
86 lines (69 loc) · 2.3 KB
/
report.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env php
<?php
ini_set('error_reporting', E_ALL|E_STRICT);
ini_set('display_errors', true);
// reads a csv file of targets
function fetch_csv($file)
{
$line = 0;
$handle = fopen($file, "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// skip blank lines
$k = count($data);
if (! $k) {
continue;
}
// retain the line of data
for ($i = 0; $i < $k; $i++) {
$list[$line][$i] = $data[$i];
}
$line ++;
}
fclose($handle);
return $list;
}
if (empty($argv[1])) {
echo "Please specify a log directory as the first argument.\n";
exit(1);
}
$log_dir = $argv[1];
// all report data: keyed by row, then by col
$report = array();
// keep track of the comparison bench average
$cmp = 99999999;
// number formatting
$format = '%8.2f';
// each of the frameworks benched
$files = glob("$log_dir/*.log");
foreach ($files as $file) {
// what is the famework name? (less the ".log" extension)
$name = substr(basename($file), 0, -4);
// output the bench on its own line
$report[$name] = array('rel' => null, 'avg' => null);
// get the CSV data, remove the field-names line
$data = fetch_csv($file);
array_shift($data);
foreach ($data as $key => $val) {
// save the req/sec
$i = $key + 1;
$report[$name][(string) $i] = sprintf($format, $val[5]);
}
// figure the average
$avg = array_sum($report[$name]) / (count($report[$name]) - 2); // -2 for rel, avg
$report[$name]['avg'] = sprintf($format, $avg);
// if this is the baseline-php report, save the comparison value
if ($name == 'baseline-php') {
$cmp = $avg;
}
}
$fwpad = 24;
// header line
$val = array(' rel', ' avg', ' 1', ' 2', ' 3', ' 4', ' 5');
echo str_pad('framework', $fwpad) . " | " . implode(" | ", $val) . "\n";
$val = array('--------', '--------', '--------', '--------', '--------', '--------', '--------');
echo str_pad('', $fwpad, '-') . " | " . implode(" | ", $val) . "\n";
// output each data line, figuring %-of-php score as we go
foreach ($report as $key => $val) {
$val['rel'] = sprintf("%8.4f", $val['avg'] / $cmp);
echo str_pad($key, $fwpad) . " | " . implode(" | ", $val) . "\n";
}