Skip to content

Commit 82abbaa

Browse files
committed
chore: add benchmark
1 parent 16c340b commit 82abbaa

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Benchmark from "benchmark";
2+
import baseline from "@babel-baseline/parser";
3+
import current from "../../lib/index.js";
4+
import { report } from "../util.mjs";
5+
6+
const suite = new Benchmark.Suite();
7+
// All codepoints in [0x4e00, 0x9ffc] are valid identifier name per Unicode 13
8+
function createInput(length) {
9+
if (length > 0x9ffc - 0x4e00) {
10+
throw new Error(
11+
`Length greater than ${
12+
0x9ffc - 0x4e00
13+
} is not supported! Consider modify the \`createInput\`.`
14+
);
15+
}
16+
let source = "";
17+
for (let i = 0; i < length; i++) {
18+
source += "let " + String.fromCharCode(0x4e00 + i) + ";";
19+
}
20+
return source;
21+
}
22+
function benchCases(name, implementation, options) {
23+
for (const length of [256, 512, 1024, 2048]) {
24+
const input = createInput(length);
25+
suite.add(`${name} ${length} length-1 let bindings`, () => {
26+
implementation.parse(input, options);
27+
});
28+
}
29+
}
30+
31+
benchCases("baseline", baseline);
32+
benchCases("current", current);
33+
34+
suite.on("cycle", report).run();

0 commit comments

Comments
 (0)