diff options
Diffstat (limited to 'benchmark')
| -rw-r--r-- | benchmark/index.js | 39 |
1 files changed, 39 insertions, 0 deletions
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()); |