Huáng Jùnliàng a8fea4037d
Faster identifier tokenizing (#13262)
* add benchmark

* perf: faster identifier tokenizing

- Mover iterator identifier parsing to the Flow plugin
- If the character is an identifier start, pass it to readWord1
2021-05-06 18:47:19 -04:00

24 lines
650 B
JavaScript

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();
function createInput(length) {
return "a;".repeat(length);
}
current.parse("a");
function benchCases(name, implementation, options) {
for (const length of [64, 128, 256, 512, 1024]) {
const input = createInput(length);
suite.add(`${name} ${length} length-1 identifiers`, () => {
implementation.parse(input, options);
});
}
}
benchCases("baseline", baseline);
benchCases("current", current);
suite.on("cycle", report).run();