forked from OKEAMAH/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.js
More file actions
28 lines (24 loc) · 775 Bytes
/
bench.js
File metadata and controls
28 lines (24 loc) · 775 Bytes
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
import { readFileSync } from "node:fs";
const [, , version, method, groupCountString = 100, groupSizeString = 10] =
process.argv;
const groupCount = Number(groupCountString);
const groupSize = Number(groupSizeString);
const { format } = await import(`./${version}/dist/index.mjs`);
const sourceText = readFileSync(
process.env.PRETTIER_PERF_FILENAME || "../../src/language-js/utils/index.js",
"utf8",
);
for (let i = 0; i < groupCount; i++) {
if (method === "serial") {
for (let i = 0; i < groupSize; i++) {
await format(sourceText, { parser: "typescript" });
}
}
if (method === "parallel") {
await Promise.allSettled(
Array.from({ length: groupSize }, () =>
format(sourceText, { parser: "typescript" }),
),
);
}
}