forked from babel/babel
/
1-length.bench.mjs
34 lines (31 loc) 路 1.05 KB
/
1-length.bench.mjs
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
import Benchmark from "benchmark";
import baseline from "@babel-baseline/parser";
import current from "../../lib/index.js";
import { report } from "../util.mjs";
const suite = new Benchmark.Suite();
// All codepoints in [0x4e00, 0x9ffc] are valid identifier name per Unicode 13
function createInput(length) {
if (length > 0x9ffc - 0x4e00) {
throw new Error(
`Length greater than ${
0x9ffc - 0x4e00
} is not supported! Consider modify the \`createInput\`.`
);
}
let source = "export { ";
for (let i = 0; i < length; i++) {
source += String.fromCharCode(0x4e00 + i) + ",";
}
return source + " } from './foo'";
}
function benchCases(name, implementation, options) {
for (const length of [256, 512, 1024, 2048]) {
const input = createInput(length);
suite.add(`${name} ${length} length-1 named export`, () => {
implementation.parse(input, options);
});
}
}
benchCases("baseline", baseline, { sourceType: "module" });
benchCases("current", current, { sourceType: "module" });
suite.on("cycle", report).run();