adventofcode/2023/04/benchmark.js

39 lines
865 B
JavaScript
Raw Normal View History

2023-12-04 17:19:52 +00:00
import fs from "fs-extra";
import { parse } from "yaml";
import { Bench } from "tinybench";
import assert from "assert";
2023-12-04 15:03:46 +00:00
2023-12-04 17:19:52 +00:00
import { solution_1 } from "./part1.js";
import { solution_2 } from "./part2.js";
2023-12-04 15:03:46 +00:00
2023-12-04 17:19:52 +00:00
const input = fs.readFileSync("./input", { encoding: "utf8" });
const solutions = parse(
fs.readFileSync("./solutions.yml", { encoding: "utf8" })
);
2023-12-04 15:03:46 +00:00
2023-12-04 17:19:52 +00:00
const bench = new Bench({ time: 10000 });
2023-12-04 15:03:46 +00:00
2023-12-04 17:19:52 +00:00
bench
.add("1", () => {
assert.equal(solution_1(input), solutions[1]);
})
.add("2", () => {
assert.equal(solution_2(input), solutions[2]);
});
2023-12-04 15:03:46 +00:00
await bench.run();
2023-12-04 17:19:52 +00:00
bench.tasks.forEach(({ result, name }) => {
console.log(
JSON.stringify({
day: 1,
year: 2023,
language: "javascript",
part: name,
timestamp: new Date().toISOString(),
time: result.mean / 1000,
persec: 1000 / result.mean,
})
);
});