import { Bench } from "tinybench"; import { renderToCanvas, StageType } from "../src/index.js"; import { createCanvas } from "canvas"; import { readFile } from "fs/promises"; import { parse } from "wmap-parser"; // We measure only the canvas rendering. const exampleSource = await readFile("test/example.wmap", "utf-8"); const hugeSource = await readFile("test/huge.wmap", "utf-8"); const exampleMap = parse(exampleSource); const hugeMap = parse(hugeSource); const canvas = createCanvas(1384, 1084); const bench = new Bench({ name: "Rendering Benchmark", time: 1000 }); bench .add("With Smart Positioning (Example)", async () => { await renderToCanvas(exampleMap, canvas); }) .add("Without Smart Positioning (Example)", async () => { await renderToCanvas(exampleMap, canvas, StageType.CERTAINTY, { smartLabelPositioning: false, }); }) .add("With Smart Positioning (Huge)", async () => { await renderToCanvas(hugeMap, canvas); }) .add("Without Smart Positioning (Huge)", async () => { await renderToCanvas(hugeMap, canvas, StageType.CERTAINTY, { smartLabelPositioning: false, }); }); await bench.run(); console.log(bench.name); console.table(bench.table());