| 1 |
import Benchmark from "benchmark"; |
| 2 |
import baseline from "@babel-baseline/generator"; |
| 3 |
import current from "@babel/generator"; |
| 4 |
import parser from "@babel/parser"; |
| 5 |
import { report } from "../../util.mjs"; |
| 6 |
import { readFileSync } from "fs"; |
| 7 |
|
| 8 |
const suite = new Benchmark.Suite(); |
| 9 |
|
| 10 |
function createInput(length) { |
| 11 |
return parser.parse( |
| 12 |
readFileSync(new URL("./jquery-3.6.txt", import.meta.url), { |
| 13 |
encoding: "utf-8", |
| 14 |
}).repeat(length) |
| 15 |
); |
| 16 |
} |
| 17 |
|
| 18 |
const inputs = [1, 4, 16, 64].map(length => ({ |
| 19 |
tag: length, |
| 20 |
body: createInput(length), |
| 21 |
})); |
| 22 |
|
| 23 |
function benchCases(name, implementation, options) { |
| 24 |
for (const input of inputs) { |
| 25 |
suite.add(`${name} ${input.tag} jquery 3.6`, () => { |
| 26 |
implementation(input.body, options); |
| 27 |
}); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
benchCases("current", current.default); |
| 32 |
benchCases("baseline", baseline.default); |
| 33 |
|
| 34 |
suite.on("cycle", report).run(); |