Skip to content

Commit c3b4a47

Browse files
committed
[test] Fixes benchmarks/suite.bench.ts
Details: - Fixes benchmark suites so that it compiles properly, and so that it compares comparable things - Updates README.md
1 parent ada65cf commit c3b4a47

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

packages/test/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ Unit testing is performed using [Vitest](https://vitest.dev/), using the [browse
2121

2222
## Benchmarking
2323

24-
Benchmarking scenarii have been written to run using the `vitest bench` command. Unfortunately, at the moment, **they don't work properly** because of [some issue](https://github.com/vitest-dev/vitest/issues/5041) with Vitest benchmark mode compatibility with the browser mode.
24+
Benchmarking scenarii have been written to run using the `vitest bench` command.
+29-26
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import Graph from "graphology";
1+
import { MultiGraph } from "graphology";
22
import { SerializedGraph } from "graphology-types";
33
import Sigma from "sigma";
44
import { bench, describe } from "vitest";
55

66
import MEDIUM_GRAPH from "../datasets/arctic.json";
77
import LARGE_GRAPH from "../datasets/large-graph.json";
88
import SMALL_GRAPH from "../datasets/les-miserables.json";
9-
import { rafNTimes } from "../helpers";
109

11-
const TIMES = 20;
10+
const ITERATIONS = 20;
1211
const METHODS = ["refresh", "render"] as const;
1312
const SIZES = ["small", "medium", "large"] as const;
1413
type Size = (typeof SIZES)[number];
@@ -24,35 +23,39 @@ const GRAPHS = {
2423
large: LARGE_GRAPH as SerializedGraph,
2524
};
2625

27-
describe("Benchmarks", () => {
28-
METHODS.forEach((method) =>
26+
METHODS.forEach((method) => {
27+
describe(`Benchmarking method "${method}"`, () => {
2928
SIZES.forEach((screenSize) =>
3029
SIZES.forEach((graphSize) => {
31-
bench(`${method}-${screenSize}-scene-${graphSize}-graph`, async () => {
32-
const container = document.createElement("div");
33-
document.body.append(container);
34-
const size = SCREEN_SIZES[screenSize];
35-
container.style.width = `${size}px`;
36-
container.style.height = `${size}px`;
37-
const graph = new Graph();
38-
graph.import(GRAPHS[graphSize] as SerializedGraph);
39-
const sigma = new Sigma(graph, container);
40-
const camera = sigma.getCamera();
30+
const size = SCREEN_SIZES[screenSize];
4131

42-
switch (method) {
43-
case "refresh":
44-
return rafNTimes(() => {
32+
const container = document.createElement("div");
33+
document.body.append(container);
34+
container.style.width = `${size}px`;
35+
container.style.height = `${size}px`;
36+
37+
const graph = new MultiGraph();
38+
graph.import(GRAPHS[graphSize] as SerializedGraph);
39+
40+
const sigma = new Sigma(graph, container);
41+
const camera = sigma.getCamera();
42+
bench(
43+
`${screenSize} scene, ${graphSize} graph`,
44+
() => {
45+
switch (method) {
46+
case "refresh":
4547
// This simulates a layout iteration, that triggers a full reindex of the graph:
4648
graph.forEachNode((node) => graph.mergeNodeAttributes(node, { x: Math.random(), y: Math.random() }));
47-
}, TIMES);
48-
case "render":
49-
return rafNTimes(() => {
49+
break;
50+
case "render":
5051
// This simulates a user interaction, that triggers a render of the graph:
5152
camera.setState({ angle: camera.angle + 0.1 });
52-
}, TIMES);
53-
}
54-
});
53+
break;
54+
}
55+
},
56+
{ iterations: ITERATIONS },
57+
);
5558
}),
56-
),
57-
);
59+
);
60+
});
5861
});

0 commit comments

Comments
 (0)