$headBenchmark) { if ($name === 'branch') { continue; } $baseInstructions = $baseSummary[$name]['instructions'] ?? null; $headInstructions = $headSummary[$name]['instructions']; $output .= "| $name | " . formatInstructions($baseInstructions) . " | " . formatInstructions($headInstructions) . " | " . formatDiff($baseInstructions, $headInstructions) . " |\n"; } return $output; } function formatInstructions(?int $instructions): string { if ($instructions === null) { return '-'; } if ($instructions > 1e6) { return sprintf('%.0fM', $instructions / 1e6); } elseif ($instructions > 1e3) { return sprintf('%.0fK', $instructions / 1e3); } else { return (string) $instructions; } } function formatDiff(?int $baseInstructions, int $headInstructions): string { if ($baseInstructions === null) { return '-'; } $instructionDiff = $headInstructions - $baseInstructions; return sprintf('%.2f%%', $instructionDiff / $baseInstructions * 100); } function find_benchmarked_commit_hash(string $repo, string $commitHash): ?string { $repeat = 100; while (true) { if ($repeat-- <= 0) { fwrite(STDERR, "Count not find benchmarked commit hash\n"); exit(1); } $summaryFile = $repo . '/' . substr($commitHash, 0, 2) . '/' . $commitHash . '/summary.json'; if (file_exists($summaryFile)) { break; } $commitHash = trim(runCommand( ['git', 'rev-parse', $commitHash . '^'], dirname(__DIR__), printCommand: false, )->stdout); } return $commitHash; } $headCommitHash = $argv[1] ?? null; $baseCommitHash = $argv[2] ?? null; $output = main($headCommitHash, $baseCommitHash); fwrite(STDOUT, $output);