Skip to content

Commit

Permalink
perf: Improve parser performance for typescript (#16072)
Browse files Browse the repository at this point in the history
* perf

* errors

* chore

* review

* review
  • Loading branch information
liuxingbaoyu committed Jan 10, 2024
1 parent 576a14a commit 0085301
Show file tree
Hide file tree
Showing 27 changed files with 22,828 additions and 834 deletions.
37 changes: 37 additions & 0 deletions benchmark/babel-parser/real-case-ts/bench.mjs
@@ -0,0 +1,37 @@
import Benchmark from "benchmark";
import baseline from "@babel-baseline/parser";
import current from "@babel/parser";
import { report } from "../../util.mjs";
import { readFileSync } from "fs";

const suite = new Benchmark.Suite();

function createInput(length) {
return readFileSync(new URL("ts-parser.txt", import.meta.url), {
encoding: "utf-8",
}).repeat(length);
}

const inputs = [1].map(length => ({
tag: length,
body: createInput(length),
}));

function benchCases(name, implementation, options) {
for (const input of inputs) {
suite.add(`${name} ${input.tag} typescript parser.ts`, () => {
implementation(input.body, {
sourceType: "module",
plugins: ["typescript"],
...options,
});
});
}
}

benchCases("current", current.parse);
benchCases("baseline", baseline.parse);
benchCases("current", current.parse);
benchCases("baseline", baseline.parse);

suite.on("cycle", report).run();

0 comments on commit 0085301

Please sign in to comment.