From 566eb2c9cce799ed8a3becc6d81560f1540eaacf Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Mon, 15 Dec 2025 16:30:22 +0100 Subject: Initial Release --- benchmark/index.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 benchmark/index.js (limited to 'benchmark') diff --git a/benchmark/index.js b/benchmark/index.js new file mode 100644 index 0000000..38e4724 --- /dev/null +++ b/benchmark/index.js @@ -0,0 +1,39 @@ +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()); -- cgit