| 1 |
import Benchmark from "benchmark"; |
| 2 |
import baseline from "@babel-baseline/parser"; |
| 3 |
import current from "@babel/parser"; |
| 4 |
import { report } from "../../util.mjs"; |
| 5 |
|
| 6 |
const suite = new Benchmark.Suite(); |
| 7 |
function createInput(length) { |
| 8 |
return "{}" + "// c\n".repeat(length); |
| 9 |
} |
| 10 |
current.parse(createInput(256), {}); |
| 11 |
function benchCases(name, implementation, options) { |
| 12 |
for (const length of [128, 256, 512, 1024]) { |
| 13 |
const input = createInput(length); |
| 14 |
const { parse } = implementation; |
| 15 |
suite.add(`${name} ${length} trailing comments`, () => { |
| 16 |
parse(input, options); |
| 17 |
}); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
benchCases("baseline", baseline); |
| 22 |
benchCases("current", current); |
| 23 |
|
| 24 |
suite.on("cycle", report).run(); |