Skip to content

Commit db09494

Browse files
committed
Add a reference resolution benchmark for a baseline
1 parent 0ebab7f commit db09494

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

bench/create-references.benchmark.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { benchmarker } from "./benchmark";
2+
import { State } from "../spec/fixtures/StateChart";
3+
4+
export default benchmarker(async (suite) => {
5+
suite
6+
.add("instantiating one reference", function () {
7+
State.createReadOnly({
8+
id: "root",
9+
childStates: [{ id: "child" }],
10+
initialChildState: "child",
11+
});
12+
})
13+
.add("instantiating deep references", function () {
14+
State.createReadOnly({
15+
id: "root",
16+
childStates: [
17+
{
18+
id: "one",
19+
childStates: [{ id: "alpha" }, { id: "beta" }, { id: "gamma", childStates: [{ id: "foxtrot" }], initialChildState: "foxtrot" }],
20+
initialChildState: "beta",
21+
},
22+
{
23+
id: "two",
24+
childStates: [{ id: "red" }, { id: "blue" }, { id: "green", childStates: [{ id: "apple" }], initialChildState: "apple" }],
25+
initialChildState: "blue",
26+
},
27+
{
28+
id: "three",
29+
childStates: [{ id: "soft" }, { id: "rough" }, { id: "bumpy", childStates: [{ id: "smelly" }], initialChildState: "smelly" }],
30+
initialChildState: "bumpy",
31+
},
32+
{ id: "four" },
33+
],
34+
initialChildState: "three",
35+
});
36+
});
37+
38+
return suite;
39+
});

spec/fixtures/StateChart.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { IAnyClassModelType } from "../../src";
2+
import { types } from "../../src";
3+
import { ClassModel, register } from "../../src/class-model";
4+
5+
// eslint-disable-next-line prefer-const
6+
export let State: IAnyClassModelType;
7+
@register
8+
class StateChartState extends ClassModel({
9+
id: types.identifier,
10+
childStates: types.array(types.late(() => State)),
11+
initialChildState: types.maybe(types.reference(types.late(() => State))),
12+
}) {}
13+
State = StateChartState;

0 commit comments

Comments
 (0)