1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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());
|