Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* perf: faster parser scope check * perf: early return for identifier length > 10 * perf: early return for normal identifier names * chore: add benchmark * Update packages/babel-parser/src/parser/expression.js
- Loading branch information
Showing
5 changed files
with
154 additions
and
35 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
packages/babel-parser/benchmark/many-identifiers/11-length.bench.mjs
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,23 @@ | ||
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(); |
23 changes: 23 additions & 0 deletions
23
packages/babel-parser/benchmark/many-identifiers/await.mjs
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,23 @@ | ||
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(); |
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
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
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