| 1 |
import Benchmark from "benchmark"; |
| 2 |
import baseline from "@babel-baseline/core"; |
| 3 |
import current from "@babel/core"; |
| 4 |
import parser from "@babel-baseline/parser"; |
| 5 |
import { report } from "../../util.mjs"; |
| 6 |
import { readFileSync } from "fs"; |
| 7 |
|
| 8 |
const suite = new Benchmark.Suite(); |
| 9 |
const fixtureName = "babel-parser-expression.txt"; |
| 10 |
|
| 11 |
function createInput() { |
| 12 |
return parser.parse( |
| 13 |
readFileSync(new URL("./" + fixtureName, import.meta.url), { |
| 14 |
encoding: "utf-8", |
| 15 |
}), |
| 16 |
{ sourceType: "module", plugins: ["flow"] } |
| 17 |
); |
| 18 |
} |
| 19 |
function benchCases(name, implementation, options) { |
| 20 |
const input = createInput(); |
| 21 |
suite.add( |
| 22 |
`${name} ${fixtureName}`, |
| 23 |
() => { |
| 24 |
implementation(input, { |
| 25 |
plugins: ["@babel/preset-env", "@babel/preset-flow"], |
| 26 |
targets: "ie 11", |
| 27 |
configFile: false, |
| 28 |
babelrc: false, |
| 29 |
...options, |
| 30 |
}); |
| 31 |
}, |
| 32 |
{ |
| 33 |
// increase minSamples for accuracy |
| 34 |
minSamples: 100, |
| 35 |
} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
benchCases("baseline", baseline.transformFromAstSync, {}); |
| 40 |
benchCases("current", current.transformFromAstSync, {}); |
| 41 |
|
| 42 |
suite.on("cycle", report).run(); |