-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathrunBenchmarks.ts
39 lines (34 loc) · 1.02 KB
/
runBenchmarks.ts
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
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { autogradBench, LOG_FILE as AUTOGRAD_LOG_FILE } from "./autograd.js";
import { serializeBenchmark } from "./serializeBenchmark.js";
const args = process.argv.slice(2);
const SAVE = args.find((arg) => arg.match(/^(--save|-s)$/));
async function bench() {
console.log("Running benchmarks...");
const benchmarks = [
{
tasks: autogradBench,
logFile: AUTOGRAD_LOG_FILE
}
];
for (const { tasks, logFile } of benchmarks) {
const results = await tasks();
if (SAVE) {
console.log(`Saving benchmark results to ${logFile}...`);
try {
const log = JSON.parse(
await readFile(join("tests", "benchmarks", logFile), "utf-8")
);
log.push(...serializeBenchmark(results));
await writeFile(
join("tests", "benchmarks", logFile),
JSON.stringify(log, null, 2)
);
} catch (err) {
console.error(err);
}
}
}
}
bench();