Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generator performance #13593

Merged
merged 11 commits into from Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions babel.config.js
Expand Up @@ -179,6 +179,10 @@ module.exports = function (api) {
plugins: ["babel-plugin-transform-charcodes"],
assumptions: parserAssumptions,
},
{
test: ["packages/babel-generator"].map(normalize),
plugins: ["babel-plugin-transform-charcodes"],
},
convertESM && {
test: [
"./packages/babel-cli",
Expand Down
25 changes: 25 additions & 0 deletions packages/babel-generator/benchmark/many-empty-statements/bench.mjs
@@ -0,0 +1,25 @@
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();
25 changes: 25 additions & 0 deletions packages/babel-generator/benchmark/many-identifiers/1-length.mjs
@@ -0,0 +1,25 @@
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();
25 changes: 25 additions & 0 deletions packages/babel-generator/benchmark/many-identifiers/25-length.mjs
@@ -0,0 +1,25 @@
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();