-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.ts
89 lines (81 loc) · 2.67 KB
/
bench.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import "npm:@total-typescript/ts-reset";
import { collapseTypes } from "./lib/collapse-types.ts";
import { emitRootTypeToString } from "./lib/emit/mod.ts";
import { parseJson } from "./lib/parse.ts";
import { Json } from "./lib/types.ts";
const blockstateFiles = Deno.readDir("./fixtures/datapack/blockstates");
const blockstateInputs = new Array<string>();
for await (const file of blockstateFiles) {
blockstateInputs.push(
await Deno.readTextFile(
`./fixtures/datapack/blockstates/${file.name}`,
),
);
}
Deno.bench("datapack/blockstates - no disk", async () => {
const type = collapseTypes(
blockstateInputs.map((input) => parseJson(JSON.parse(input) as Json)),
);
await emitRootTypeToString("rust", type, []);
});
const blockModelFiles = Deno.readDir("./fixtures/datapack/models/block");
const itemModelFiles = Deno.readDir("./fixtures/datapack/models/item");
const modelInputs = new Array<string>();
for await (const file of blockModelFiles) {
modelInputs.push(
await Deno.readTextFile(
`./fixtures/datapack/models/block/${file.name}`,
),
);
}
for await (const file of itemModelFiles) {
modelInputs.push(
await Deno.readTextFile(
`./fixtures/datapack/models/item/${file.name}`,
),
);
}
Deno.bench("datapack/models - no disk", async () => {
const type = collapseTypes(
modelInputs.map((input) => parseJson(JSON.parse(input) as Json)),
);
await emitRootTypeToString("rust", type, []);
});
Deno.bench("datapack/blockstates", async () => {
const blockstateFiles = Deno.readDir("./fixtures/datapack/blockstates");
const blockstateInputs = new Array<string>();
for await (const file of blockstateFiles) {
blockstateInputs.push(
await Deno.readTextFile(
`./fixtures/datapack/blockstates/${file.name}`,
),
);
}
const type = collapseTypes(
blockstateInputs.map((input) => parseJson(JSON.parse(input) as Json)),
);
await emitRootTypeToString("rust", type, []);
});
Deno.bench("datapack/models", async () => {
const blockModelFiles = Deno.readDir("./fixtures/datapack/models/block");
const itemModelFiles = Deno.readDir("./fixtures/datapack/models/item");
const modelInputs = new Array<string>();
for await (const file of blockModelFiles) {
modelInputs.push(
await Deno.readTextFile(
`./fixtures/datapack/models/block/${file.name}`,
),
);
}
for await (const file of itemModelFiles) {
modelInputs.push(
await Deno.readTextFile(
`./fixtures/datapack/models/item/${file.name}`,
),
);
}
const type = collapseTypes(
modelInputs.map((input) => parseJson(JSON.parse(input) as Json)),
);
await emitRootTypeToString("rust", type, []);
});