Polish benchmark reporting

This commit is contained in:
Chirag Aggarwal
2026-04-21 16:58:31 +05:30
parent ef08d5a04c
commit 30cfbb2d99
2 changed files with 31 additions and 4 deletions
+24 -2
View File
@@ -746,8 +746,30 @@ jobs:
docker run --rm -i -v "$PWD:/scripts" -w /scripts ${{ env.IMAGE }}:after php <<'PHP' > benchmark-comment.txt
<?php
$before = json_decode(file_get_contents('benchmark-before-summary.json'), true);
$after = json_decode(file_get_contents('benchmark-after-summary.json'), true);
function read_summary(string $path): array
{
if (!is_file($path)) {
fwrite(STDERR, "Missing benchmark summary: {$path}\n");
exit(1);
}
try {
$summary = json_decode(file_get_contents($path), true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $error) {
fwrite(STDERR, "Invalid benchmark summary {$path}: {$error->getMessage()}\n");
exit(1);
}
if (!is_array($summary)) {
fwrite(STDERR, "Invalid benchmark summary {$path}: expected JSON object\n");
exit(1);
}
return $summary;
}
$before = read_summary('benchmark-before-summary.json');
$after = read_summary('benchmark-after-summary.json');
function metric_value(?array $data, string $metric, string $stat): mixed
{
+7 -2
View File
@@ -290,7 +290,12 @@ final class HttpBenchmark
$context = $this->setup();
for ($i = 0; $i < $this->iterations * $this->vus; $i++) {
$this->curatedFlows($context);
try {
$this->curatedFlows($context);
} catch (Throwable $error) {
$exitCode = 1;
fwrite(STDERR, 'Iteration ' . ($i + 1) . ' failed: ' . $error->getMessage() . PHP_EOL);
}
}
} catch (Throwable $error) {
$exitCode = 1;
@@ -1216,7 +1221,7 @@ final class HttpBenchmark
'',
];
return implode(PHP_EOL, array_filter($lines, fn (string $line): bool => $line !== '')) . PHP_EOL;
return implode(PHP_EOL, $lines) . PHP_EOL;
}
private function comparisonTable(?array $before, array $after): string