| 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 "const a = /" + "[/\\\\]".repeat(length / 4) + "/igsudm"; |
| 9 | } |
| 10 | function benchCases(name, implementation, options) { |
| 11 | for (const length of [256, 512, 1024, 2048]) { |
| 12 | const input = createInput(length); |
| 13 | suite.add(`${name} ${length}-size RegExp literal `, () => { |
| 14 | implementation.parse(input, options); |
| 15 | }); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | benchCases("baseline", baseline); |
| 20 | benchCases("current", current); |
| 21 | |
| 22 | suite.on("cycle", report).run(); |