Skip to content

Commit

Permalink
chore: bench traverse modules
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Feb 17, 2025
1 parent 7336fd7 commit 7e15ba5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
55 changes: 55 additions & 0 deletions tests/bench/ts-react-hmr.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { type Compiler, type Compilation, rspack } from "@rspack/core";
import { beforeAll, bench, describe } from "vitest";
import rspackConfig from "./fixtures/ts-react/rspack.config";

let thisCompiler: Compiler;
let theCompilation: Compilation;

beforeAll(() => {
return new Promise((resolve, reject) => {
thisCompiler = rspack(
{
...rspackConfig,
mode: "production",
plugins: [
...(rspackConfig.plugins ?? []),
compiler => {
compiler.hooks.compilation.tap("PLUGIN", compilation => {
theCompilation = compilation;
});
}
]
}
);
thisCompiler.run((err, stats) => {
if (err) {
reject(err);
}
if (stats?.hasErrors()) {
reject(new Error(stats.toString({})));
}
resolve(undefined);
});
for (const module of theCompilation.modules) {}
});
});

beforeEach(() => {
return new Promise((resolve, reject) => {
thisCompiler.run((err, stats) => {
if (err) {
reject(err);
}
if (stats?.hasErrors()) {
reject(new Error(stats.toString({})));
}
resolve(undefined);
});
});
});

describe("TypeScript React project HMR", () => {
bench("traverse modules (HMR)", () => {
for (const module of theCompilation.modules) {}
});
});
6 changes: 5 additions & 1 deletion tests/bench/ts-react.bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import rspackConfig from "./fixtures/ts-react/rspack.config";

let theCompilation: Compilation;

beforeAll(() => {
beforeEach(() => {
return new Promise((resolve, reject) =>
rspack(
{
Expand Down Expand Up @@ -85,4 +85,8 @@ describe("TypeScript React project", () => {
}
}
});

bench("traverse modules (Build)", () => {
for (const module of theCompilation.modules) {}
});
});

0 comments on commit 7e15ba5

Please sign in to comment.