Allow benchmark with esm building (#16101)

* perf

* improve
This commit is contained in:
liuxingbaoyu
2023-11-15 12:57:35 -05:00
committed by GitHub
parent 5ad3b1aa0d
commit b5d2811950
13 changed files with 3363 additions and 32 deletions
@@ -2,6 +2,8 @@ name: E2E tests (breaking, esm)
on:
push:
branches:
- main
pull_request:
permissions:
+2
View File
@@ -2,6 +2,8 @@ name: E2E tests
on:
push:
branches:
- main
pull_request:
permissions:
@@ -0,0 +1,47 @@
import Benchmark from "benchmark";
import { readFileSync } from "fs";
import {
report,
currentCore,
baselineCore,
currentParser,
} from "../../util.mjs";
const suite = new Benchmark.Suite();
function createInput() {
return currentParser.parse(
readFileSync(
new URL("./babel-parser-tokenizer-index.txt", import.meta.url),
{
encoding: "utf-8",
}
),
{ sourceType: "module", plugins: ["typescript"] }
);
}
const input = createInput();
function benchCases(name, implementation, options = {}) {
suite.add(
name,
() => {
implementation(input, {
plugins: ["@babel/preset-env", "@babel/preset-typescript"],
targets: "node 6",
configFile: false,
babelrc: false,
...options,
});
},
{
// increase minSamples for accuracy
minSamples: 100,
}
);
}
benchCases("baseline", baselineCore.transformFromAstSync);
benchCases("current", currentCore.transformFromAstSync);
suite.on("cycle", report).run();
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,39 @@
import { readFileSync } from "fs";
import {
currentCore,
baselineCore,
presetTypescript,
Benchmark,
} from "../../util.mjs";
import commonjs from "@babel/plugin-transform-modules-commonjs";
const benchmark = new Benchmark();
const input = readFileSync(
new URL("./babel-parser-tokenizer-index.txt", import.meta.url),
"utf-8"
);
function benchCases(name, implementation, options = {}) {
benchmark.add(
name,
() => {
implementation(input, {
presets: [presetTypescript],
plugins: [commonjs],
targets: "node 6",
configFile: false,
babelrc: false,
...options,
});
},
{
// increase minSamples for accuracy
minSamples: 100,
}
);
}
benchCases("baseline", baselineCore.transformSync);
benchCases("current", currentCore.transformSync);
benchmark.run();
+2
View File
@@ -15,8 +15,10 @@
"@babel/helper-compilation-targets": "workspace:^",
"@babel/helper-validator-identifier": "workspace:^",
"@babel/parser": "workspace:^",
"@babel/plugin-transform-modules-commonjs": "workspace:^",
"@babel/preset-env": "workspace:^",
"@babel/preset-flow": "workspace:^",
"@babel/preset-typescript": "workspace:^",
"@babel/traverse": "workspace:^",
"@babel/types": "workspace:^",
"benchmark": "^2.1.4"
+47
View File
@@ -1,3 +1,18 @@
import * as currentTypes from "@babel/types";
import * as baselineTypes from "@babel-baseline/types";
import * as currentParser from "@babel/parser";
import * as baselineParser from "@babel-baseline/parser";
import * as currentGenerator from "@babel/generator";
import * as baselineGenerator from "@babel-baseline/generator";
import * as currentCore from "@babel/core";
import * as baselineCore from "@babel-baseline/core";
import * as currentTraverse from "@babel/traverse";
import * as baselineTraverse from "@babel-baseline/traverse";
import presetEnv from "@babel/preset-env";
import presetTypescript from "@babel/preset-typescript";
import benchmark from "benchmark";
export function report(event) {
const bench = event.target;
const timeMs = bench.stats.mean * 1000;
@@ -15,3 +30,35 @@ function formatNumber(x) {
if (x < 100) return `${Math.round(x * 100) / 100}`;
return `${Math.round(x)}`.replace(/\d(?=(?:\d{3})+$)/g, "$&_");
}
class Benchmark {
constructor() {
this.suite = new benchmark.Suite();
}
add(name, fn, options) {
this.suite.add(name, fn, options);
}
run() {
this.suite.on("cycle", report);
this.suite.on("error", function (event) {
console.error(event.target.error);
});
this.suite.run();
}
}
export {
currentTypes,
baselineTypes,
currentParser,
baselineParser,
currentGenerator,
baselineGenerator,
currentCore,
baselineCore,
currentTraverse,
baselineTraverse,
presetEnv,
presetTypescript,
Benchmark,
};
@@ -25,17 +25,6 @@ initializeE2Egit
yarn
# Does not trap on error
node --experimental-fetch scripts/integration-tests/utils/e2e-check.js && :; ret=$?
if [ $ret -eq 10 ]; then
cleanup
exit 0
elif [ $ret -ne 0 ]; then
cleanup
exit 1
fi
startLocalRegistry "$PWD"/scripts/integration-tests/verdaccio-config.yml
loginLocalRegistry
@@ -1,21 +0,0 @@
import fs from "fs";
const resp = await fetch(
"https://raw.githubusercontent.com/babel/babel/main/package.json"
);
const mainRepoPackageJson = await resp.json();
if (
mainRepoPackageJson.version !==
JSON.parse(fs.readFileSync("package.json")).version
) {
if (process.env.GITHUB_REPOSITORY === "babel/babel") {
console.error("The branch is not up to date with main, please rebase");
process.exitCode = 1;
} else {
console.error(
"The branch is not up to date with main of babel/babel, skipping"
);
process.exitCode = 10;
}
}
+2
View File
@@ -193,8 +193,10 @@ __metadata:
"@babel/helper-compilation-targets": "workspace:^"
"@babel/helper-validator-identifier": "workspace:^"
"@babel/parser": "workspace:^"
"@babel/plugin-transform-modules-commonjs": "workspace:^"
"@babel/preset-env": "workspace:^"
"@babel/preset-flow": "workspace:^"
"@babel/preset-typescript": "workspace:^"
"@babel/traverse": "workspace:^"
"@babel/types": "workspace:^"
benchmark: "npm:^2.1.4"