Faster readRegexp (#13453)

This commit is contained in:
Huáng Jùnliàng
2021-06-10 19:00:21 -04:00
committed by GitHub
parent 0eb2853732
commit 6c8b2336f6
5 changed files with 82 additions and 31 deletions

View File

@@ -0,0 +1,22 @@
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 "const a = /" + "[/\\\\]".repeat(length / 4) + "/igsudm";
}
function benchCases(name, implementation, options) {
for (const length of [256, 512, 1024, 2048]) {
const input = createInput(length);
suite.add(`${name} ${length}-size RegExp literal `, () => {
implementation.parse(input, options);
});
}
}
benchCases("baseline", baseline);
benchCases("current", current);
suite.on("cycle", report).run();

View File

@@ -0,0 +1,22 @@
import Benchmark from "benchmark";
import baseline from "../../lib/index-v2.js";
import current from "../../lib/index.js";
import { report } from "../util.mjs";
const suite = new Benchmark.Suite();
function createInput(length) {
return "/x/dgimsuy;".repeat(length);
}
function benchCases(name, implementation, options) {
for (const length of [256, 512, 1024, 2048]) {
const input = createInput(length);
suite.add(`${name} ${length} small regexp literal with all flags`, () => {
implementation.parse(input, options);
});
}
}
benchCases("baseline", baseline);
benchCases("current", current);
suite.on("cycle", report).run();