({ args })
| 57 | json: { type: "boolean", description: "Output results as JSON", default: false }, |
| 58 | }, |
| 59 | async run({ args }) { |
| 60 | // ── Resolve project ────────────────────────────────────────────────── |
| 61 | const project = resolveProject(args.dir); |
| 62 | |
| 63 | // ── Parse runs ─────────────────────────────────────────────────────── |
| 64 | const runsPerConfig = parseInt(args.runs ?? "3", 10); |
| 65 | if (isNaN(runsPerConfig) || runsPerConfig < 1 || runsPerConfig > 20) { |
| 66 | errorBox("Invalid runs", `Got "${args.runs ?? "3"}". Must be between 1 and 20.`); |
| 67 | process.exit(1); |
| 68 | } |
| 69 | |
| 70 | const jsonOutput = args.json ?? false; |
| 71 | |
| 72 | // ── Temp output for benchmark renders ──────────────────────────────── |
| 73 | const benchDir = resolve("renders", ".benchmark"); |
| 74 | |
| 75 | // ── Load producer ──────────────────────────────────────────────────── |
| 76 | let producer: Awaited<ReturnType<typeof loadProducer>> | null = null; |
| 77 | try { |
| 78 | producer = await loadProducer(); |
| 79 | } catch { |
| 80 | if (jsonOutput) { |
| 81 | console.log( |
| 82 | JSON.stringify({ error: "Producer module not available. Is the project built?" }), |
| 83 | ); |
| 84 | } else { |
| 85 | errorBox( |
| 86 | "Producer module not available", |
| 87 | "The rendering pipeline could not be loaded.", |
| 88 | "Ensure @hyperframes/producer is built and linked.", |
| 89 | ); |
| 90 | } |
| 91 | process.exit(1); |
| 92 | } |
| 93 | |
| 94 | // ── Print header ───────────────────────────────────────────────────── |
| 95 | if (!jsonOutput) { |
| 96 | console.log(""); |
| 97 | console.log( |
| 98 | c.accent("\u25C6") + |
| 99 | " Benchmarking " + |
| 100 | c.accent(project.name) + |
| 101 | c.dim(` (${runsPerConfig} runs each)`), |
| 102 | ); |
| 103 | console.log(""); |
| 104 | } |
| 105 | |
| 106 | // ── Run benchmarks ─────────────────────────────────────────────────── |
| 107 | const results: ConfigResult[] = []; |
| 108 | |
| 109 | for (const config of DEFAULT_CONFIGS) { |
| 110 | const runs: RunResult[] = []; |
| 111 | let failures = 0; |
| 112 | |
| 113 | const s = !jsonOutput ? clack.spinner() : undefined; |
| 114 | s?.start(`Benchmarking ${config.label}...`); |
| 115 | |
| 116 | for (let i = 0; i < runsPerConfig; i++) { |
nothing calls this directly
no test coverage detected