adventofcode/2023/preset/day/templates/js/benchmark.js

34 lines
850 B
JavaScript
Raw Normal View History

2023-12-04 15:03:46 +00:00
import fs from 'fs-extra';
import { parse } from 'yaml';
import { Bench } from 'tinybench';
import assert from 'assert';
import { solution_1 } from './part1.js';
import { solution_2 } from './part2.js';
const input = fs.readFileSync('./input',{ encoding: 'utf8'});
const solutions = parse( fs.readFileSync('./solutions.yml',{encoding:'utf8'}));
const bench = new Bench({time: 10000});
bench.add( '1', () => {
assert.equal(solution_1(input),solutions[1])
})
.add( '2', () => {
assert.equal(solution_2(input),solutions[2])
});
await bench.run();
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,
}));
})