Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: Improve parser performance for typescript (#16072)
* perf * errors * chore * review * review
- Loading branch information
1 parent
576a14a
commit 0085301
Showing
27 changed files
with
22,828 additions
and
834 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
Oops, something went wrong.