chore: reorganize benchmarks (#13606)
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/generator";
|
||||
import current from "../../lib/index.js";
|
||||
import parser from "@babel/parser";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function createInput(length) {
|
||||
return parser.parse(";".repeat(length));
|
||||
}
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} empty statements`, () => {
|
||||
implementation(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline.default);
|
||||
benchCases("current", current.default);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,25 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/generator";
|
||||
import current from "../../lib/index.js";
|
||||
import parser from "@babel/parser";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function createInput(length) {
|
||||
return parser.parse("a;".repeat(length));
|
||||
}
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} 1-length identifiers`, () => {
|
||||
implementation(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline.default);
|
||||
benchCases("current", current.default);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,25 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/generator";
|
||||
import current from "../../lib/index.js";
|
||||
import parser from "@babel/parser";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function createInput(length) {
|
||||
return parser.parse("parseMaybeImportAssertion;".repeat(length));
|
||||
}
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} 25-length identifiers`, () => {
|
||||
implementation(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline.default);
|
||||
benchCases("current", current.default);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,30 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel-baseline/generator";
|
||||
import current from "../../lib/index.js";
|
||||
import parser from "@babel/parser";
|
||||
import { report } from "../util.mjs";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function createInput(length) {
|
||||
return parser.parse(
|
||||
readFileSync(new URL("./jquery-3.6.txt", import.meta.url), {
|
||||
encoding: "utf-8",
|
||||
}).repeat(length)
|
||||
);
|
||||
}
|
||||
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [1, 2]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} jquery 3.6`, () => {
|
||||
implementation(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline.default);
|
||||
benchCases("current", current.default);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,17 +0,0 @@
|
||||
export function report(event) {
|
||||
const bench = event.target;
|
||||
const timeMs = bench.stats.mean * 1000;
|
||||
const time =
|
||||
timeMs < 10
|
||||
? `${Math.round(timeMs * 1000) / 1000}ms`
|
||||
: `${Math.round(timeMs)}ms`;
|
||||
const msg = `${bench.name}: ${formatNumber(bench.hz)} ops/sec ±${
|
||||
Math.round(bench.stats.rme * 100) / 100
|
||||
}% (${time})`;
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
function formatNumber(x) {
|
||||
if (x < 100) return `${Math.round(x * 100) / 100}`;
|
||||
return `${Math.round(x)}`.replace(/\d(?=(?:\d{3})+$)/g, "$&_");
|
||||
}
|
||||
@@ -24,12 +24,10 @@
|
||||
"source-map": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel-baseline/generator": "npm:@babel/generator@7.14.5",
|
||||
"@babel/helper-fixtures": "workspace:*",
|
||||
"@babel/parser": "workspace:*",
|
||||
"@types/jsesc": "^2.5.0",
|
||||
"@types/source-map": "^0.5.0",
|
||||
"benchmark": "^2.1.4",
|
||||
"charcodes": "^0.2.0"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
benchmark
|
||||
src
|
||||
test
|
||||
*.log
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import "./isIdentifierChar.bench.mjs";
|
||||
import "./isIdentifierStart.bench.mjs";
|
||||
import "./isIdentifierName.bench.mjs";
|
||||
@@ -1,31 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel/helper-validator-identifier-baseline";
|
||||
import current from "../lib/index.js";
|
||||
import { report } from "./util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementation, name) {
|
||||
suite.add(name + "#isIdentifierChar on 4 ASCII characters", () => {
|
||||
implementation.isIdentifierChar(0x61);
|
||||
implementation.isIdentifierChar(0x7b);
|
||||
implementation.isIdentifierChar(0x5f);
|
||||
implementation.isIdentifierChar(0x24);
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierChar on 4 non-ASCII characters", () => {
|
||||
implementation.isIdentifierChar(0x80);
|
||||
implementation.isIdentifierChar(0x4e00);
|
||||
implementation.isIdentifierChar(0xffff);
|
||||
implementation.isIdentifierChar(0x10000);
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierChar on TIP character", () => {
|
||||
implementation.isIdentifierChar(0x30000);
|
||||
});
|
||||
}
|
||||
|
||||
benchCases(baseline, "baseline");
|
||||
benchCases(current, "current");
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,30 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel/helper-validator-identifier-baseline";
|
||||
import current from "../lib/index.js";
|
||||
import { report } from "./util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementation, name) {
|
||||
suite.add(name + "#isIdentifierName on 2 short ASCII words", () => {
|
||||
implementation.isIdentifierName("aforementioned");
|
||||
implementation.isIdentifierName("zap cannon");
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierName on 1 long ASCII words", () => {
|
||||
implementation.isIdentifierName(
|
||||
"Pneumonoultramicroscopicsilicovolcanoconiosis"
|
||||
);
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierName on 3 non-ASCII words", () => {
|
||||
implementation.isIdentifierName("مذكور أعلاه");
|
||||
implementation.isIdentifierName("cañón de zap");
|
||||
implementation.isIdentifierName("𠡦𠧋𡆠囝〇𠁈𢘑𤯔𠀑埊");
|
||||
});
|
||||
}
|
||||
|
||||
benchCases(baseline, "baseline");
|
||||
benchCases(current, "current");
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,31 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel/helper-validator-identifier-baseline";
|
||||
import current from "../lib/index.js";
|
||||
import { report } from "./util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementation, name) {
|
||||
suite.add(name + "#isIdentifierStart on 4 ASCII characters", () => {
|
||||
implementation.isIdentifierStart(0x61);
|
||||
implementation.isIdentifierStart(0x7b);
|
||||
implementation.isIdentifierStart(0x5f);
|
||||
implementation.isIdentifierStart(0x24);
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierStart on 4 non-ASCII characters", () => {
|
||||
implementation.isIdentifierStart(0x80);
|
||||
implementation.isIdentifierStart(0x4e00);
|
||||
implementation.isIdentifierStart(0xffff);
|
||||
implementation.isIdentifierStart(0x10000);
|
||||
});
|
||||
|
||||
suite.add(name + "#isIdentifierStart on TIP character", () => {
|
||||
implementation.isIdentifierStart(0x30000);
|
||||
});
|
||||
}
|
||||
|
||||
benchCases(baseline, "baseline");
|
||||
benchCases(current, "current");
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,27 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel/helper-validator-identifier-baseline";
|
||||
import current from "../lib/index.js";
|
||||
import { report } from "./util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementation, name) {
|
||||
suite.add(name + "#isKeyword on 4 keywords", () => {
|
||||
implementation.isKeyword("debugger");
|
||||
implementation.isKeyword("throw");
|
||||
implementation.isKeyword("extends");
|
||||
implementation.isKeyword("instanceof");
|
||||
});
|
||||
|
||||
suite.add(name + "#isKeyword on 4 non-keywords", () => {
|
||||
implementation.isKeyword("debuggerr");
|
||||
implementation.isKeyword("threw");
|
||||
implementation.isKeyword("extend");
|
||||
implementation.isKeyword("instanceOf");
|
||||
});
|
||||
}
|
||||
|
||||
benchCases(baseline, "baseline");
|
||||
benchCases(current, "current");
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,27 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "@babel/helper-validator-identifier-baseline";
|
||||
import current from "../lib/index.js";
|
||||
import { report } from "./util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
|
||||
function benchCases(implementation, name) {
|
||||
suite.add(name + "#isStrictBindReservedWord on 4 keywords", () => {
|
||||
implementation.isStrictBindReservedWord("arguments");
|
||||
implementation.isStrictBindReservedWord("eval");
|
||||
implementation.isStrictBindReservedWord("implements");
|
||||
implementation.isStrictBindReservedWord("instanceof");
|
||||
});
|
||||
|
||||
suite.add(name + "#isStrictBindReservedWord on 4 non-keywords", () => {
|
||||
implementation.isStrictBindReservedWord("argumentss");
|
||||
implementation.isStrictBindReservedWord("evals");
|
||||
implementation.isStrictBindReservedWord("implement");
|
||||
implementation.isStrictBindReservedWord("instanceOf");
|
||||
});
|
||||
}
|
||||
|
||||
benchCases(baseline, "baseline");
|
||||
benchCases(current, "current");
|
||||
|
||||
suite.on("cycle", report).run({ async: false });
|
||||
@@ -1,17 +0,0 @@
|
||||
export function report(event) {
|
||||
const bench = event.target;
|
||||
const timeMs = bench.stats.mean * 1000;
|
||||
const time =
|
||||
timeMs < 10
|
||||
? `${Math.round(timeMs * 1000) / 1000}ms`
|
||||
: `${Math.round(timeMs)}ms`;
|
||||
const msg = `${bench.name}: ${formatNumber(bench.hz)} ops/sec ±${
|
||||
Math.round(bench.stats.rme * 100) / 100
|
||||
}% (${time})`;
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
function formatNumber(x) {
|
||||
if (x < 100) return `${Math.round(x * 100) / 100}`;
|
||||
return `${Math.round(x)}`.replace(/\d(?=(?:\d{3})+$)/g, "$&_");
|
||||
}
|
||||
@@ -14,9 +14,7 @@
|
||||
"main": "./lib/index.js",
|
||||
"exports": "./lib/index.js",
|
||||
"devDependencies": {
|
||||
"@babel/helper-validator-identifier-baseline": "npm:@babel/helper-validator-identifier@7.10.4",
|
||||
"@unicode/unicode-13.0.0": "^1.0.6",
|
||||
"benchmark": "^2.1.4",
|
||||
"charcodes": "^0.2.0"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
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();
|
||||
@@ -1,22 +0,0 @@
|
||||
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 "type A = " + "| (x) => void".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} arrow function types`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline, { plugins: ["flow"] });
|
||||
benchCases("current", current, { plugins: ["flow"] });
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
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 "async () => {};".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} async arrow functions`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,34 +0,0 @@
|
||||
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 = "class C { ";
|
||||
for (let i = 0; i < length; i++) {
|
||||
source += "#" + String.fromCharCode(0x4e00 + i) + ";";
|
||||
}
|
||||
return source + " }";
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} length-1 private properties`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,19 +0,0 @@
|
||||
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 benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
suite.add(`${name} ${length} empty statement`, () => {
|
||||
implementation.parse(";".repeat(length), options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current + attachComment: false", current, { attachComment: false });
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,23 +0,0 @@
|
||||
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();
|
||||
@@ -1,23 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "../../lib/index-main.js";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "abcde12345z;".repeat(length);
|
||||
}
|
||||
current.parse("a");
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [64, 128, 256, 512]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} length-11 identifiers`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,23 +0,0 @@
|
||||
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 "aa;".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-2 identifiers`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,23 +0,0 @@
|
||||
import Benchmark from "benchmark";
|
||||
import baseline from "../../lib/index-main.js";
|
||||
import current from "../../lib/index.js";
|
||||
import { report } from "../util.mjs";
|
||||
|
||||
const suite = new Benchmark.Suite();
|
||||
function createInput(length) {
|
||||
return "await;".repeat(length);
|
||||
}
|
||||
current.parse("a");
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [64, 128, 256, 512]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} await identifier`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
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 "[,\n// c\n".repeat(length) + "\n]".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} nested inner comments`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,24 +0,0 @@
|
||||
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 "[" + "// c\n".repeat(length) + "]";
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} inner comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,24 +0,0 @@
|
||||
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 "// c\n{\n".repeat(length) + "}".repeat(length);
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} nested leading comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,24 +0,0 @@
|
||||
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 "// c\n".repeat(length) + "{}";
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} leading comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,27 +0,0 @@
|
||||
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 "\n// c\na".repeat(length);
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(
|
||||
`${name} ${length} leading comments + ${length - 1} trailing comments`,
|
||||
() => {
|
||||
parse(input, options);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,22 +0,0 @@
|
||||
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 "{ let foecnatsni };".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [64, 128, 256, 512]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} let and length-10 binding identifiers`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,34 +0,0 @@
|
||||
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 = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
source += "let " + String.fromCharCode(0x4e00 + i) + ";";
|
||||
}
|
||||
return source;
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [256, 512, 1024, 2048]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} length-1 let bindings`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,34 +0,0 @@
|
||||
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();
|
||||
@@ -1,22 +0,0 @@
|
||||
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();
|
||||
@@ -1,22 +0,0 @@
|
||||
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 "{".repeat(length) + "} // c\n".repeat(length);
|
||||
}
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
suite.add(`${name} ${length} nested trailing comments`, () => {
|
||||
implementation.parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,24 +0,0 @@
|
||||
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 "{}" + "// c\n".repeat(length);
|
||||
}
|
||||
current.parse(createInput(256), {});
|
||||
function benchCases(name, implementation, options) {
|
||||
for (const length of [128, 256, 512, 1024]) {
|
||||
const input = createInput(length);
|
||||
const { parse } = implementation;
|
||||
suite.add(`${name} ${length} trailing comments`, () => {
|
||||
parse(input, options);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
benchCases("baseline", baseline);
|
||||
benchCases("current", current);
|
||||
|
||||
suite.on("cycle", report).run();
|
||||
@@ -1,17 +0,0 @@
|
||||
export function report(event) {
|
||||
const bench = event.target;
|
||||
const timeMs = bench.stats.mean * 1000;
|
||||
const time =
|
||||
timeMs < 10
|
||||
? `${Math.round(timeMs * 1000) / 1000}ms`
|
||||
: `${Math.round(timeMs)}ms`;
|
||||
const msg = `${bench.name}: ${formatNumber(bench.hz)} ops/sec ±${
|
||||
Math.round(bench.stats.rme * 100) / 100
|
||||
}% (${time})`;
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
function formatNumber(x) {
|
||||
if (x < 100) return `${Math.round(x * 100) / 100}`;
|
||||
return `${Math.round(x)}`.replace(/\d(?=(?:\d{3})+$)/g, "$&_");
|
||||
}
|
||||
@@ -33,11 +33,9 @@
|
||||
"node": ">=6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel-baseline/parser": "npm:@babel/parser@^7.14.5",
|
||||
"@babel/code-frame": "workspace:*",
|
||||
"@babel/helper-fixtures": "workspace:*",
|
||||
"@babel/helper-validator-identifier": "workspace:*",
|
||||
"benchmark": "^2.1.4",
|
||||
"charcodes": "^0.2.0"
|
||||
},
|
||||
"bin": "./bin/babel-parser.js"
|
||||
|
||||
Reference in New Issue
Block a user