| 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 "<t a={x}>{y}".repeat(length) + "</t>".repeat(length); |
| 9 |
} |
| 10 |
function benchCases(name, implementation, options) { |
| 11 |
for (const length of [128, 256, 512, 1024]) { |
| 12 |
const input = createInput(length); |
| 13 |
suite.add( |
| 14 |
`${name} ${length} nested jsx elements with one attribute and text`, |
| 15 |
() => { |
| 16 |
implementation.parse(input, options); |
| 17 |
} |
| 18 |
); |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
benchCases("baseline", baseline, { plugins: ["jsx"] }); |
| 23 |
benchCases("current", current, { plugins: ["jsx"] }); |
| 24 |
|
| 25 |
suite.on("cycle", report).run(); |