|
| 1 | +#!/usr/bin/env -S deno run -A |
| 2 | + |
| 3 | +const CONFIGS = [ |
| 4 | + "tsconfig.baseline.json", |
| 5 | + "tsconfig.key.json", |
| 6 | + "tsconfig.anycell.json", |
| 7 | + "tsconfig.schema.json", |
| 8 | + "tsconfig.ikeyable-cell.json", |
| 9 | + "tsconfig.ikeyable-schema.json", |
| 10 | + "tsconfig.ikeyable-realistic.json", |
| 11 | +] as const; |
| 12 | + |
| 13 | +const scriptDir = new URL(".", import.meta.url); |
| 14 | +const cwd = scriptDir.pathname; |
| 15 | + |
| 16 | +function fromFileUrl(url: URL): string { |
| 17 | + if (url.protocol !== "file:") throw new TypeError("URL must be a file URL"); |
| 18 | + const path = decodeURIComponent(url.pathname); |
| 19 | + if (Deno.build.os === "windows") { |
| 20 | + return path.slice(1).replaceAll("/", "\\"); |
| 21 | + } |
| 22 | + return path; |
| 23 | +} |
| 24 | + |
| 25 | +const tscPath = fromFileUrl( |
| 26 | + new URL( |
| 27 | + "../../../node_modules/.deno/typescript@5.8.3/node_modules/typescript/bin/tsc", |
| 28 | + import.meta.url, |
| 29 | + ), |
| 30 | +); |
| 31 | + |
| 32 | +const decoder = new TextDecoder(); |
| 33 | +const encoder = new TextEncoder(); |
| 34 | + |
| 35 | +async function runScenario(config: string) { |
| 36 | + console.log(`# ${config}`); |
| 37 | + |
| 38 | + const command = new Deno.Command(tscPath, { |
| 39 | + args: ["--project", config, "--extendedDiagnostics", "--pretty", "false"], |
| 40 | + cwd, |
| 41 | + }); |
| 42 | + |
| 43 | + const { code, stdout, stderr } = await command.output(); |
| 44 | + if (code !== 0) { |
| 45 | + const err = decoder.decode(stderr); |
| 46 | + console.error(err); |
| 47 | + throw new Error(`Benchmark failed for ${config}`); |
| 48 | + } |
| 49 | + |
| 50 | + const output = decoder.decode(stdout); |
| 51 | + console.log(output); |
| 52 | + |
| 53 | + const summary: string[] = []; |
| 54 | + for (const line of output.split("\n")) { |
| 55 | + if (line.startsWith("Instantiations:")) { |
| 56 | + summary.push(line.trim()); |
| 57 | + } else if (line.startsWith("Check time:")) { |
| 58 | + summary.push(line.trim()); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + if (summary.length > 0) { |
| 63 | + await Deno.stdout.write( |
| 64 | + encoder.encode( |
| 65 | + `${summary.join(" | ")}\n----------------------------------------\n\n`, |
| 66 | + ), |
| 67 | + ); |
| 68 | + } else { |
| 69 | + console.log("----------------------------------------\n"); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +for (const config of CONFIGS) { |
| 74 | + await runScenario(config); |
| 75 | +} |
0 commit comments