Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Jan 4, 2025
1 parent 99f77c8 commit 3ae02ec
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 1 deletion.
27 changes: 27 additions & 0 deletions tests/bench/bench.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Bench } from "tinybench";
import { withCodSpeed } from "@codspeed/tinybench-plugin";

function fibonacci(n) {
if (n < 2) {
return n;
}
return fibonacci(n - 1) + fibonacci(n - 2);
}

const bench = withCodSpeed(new Bench());

bench
.add("fibonacci10", () => {
console.log("fibonacci10")
fibonacci(10);
})
// .add("fibonacci15", () => {
// fibonacci(15);
// });

bench.addEventListener("start", () => {
console.log("hello")
});

await bench.run();
console.table(bench.table());
1 change: 1 addition & 0 deletions tests/bench/fixtures/vanilla-js/one.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("one");
67 changes: 67 additions & 0 deletions tests/bench/loader.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { join } from 'node:path';
import { rspack } from "@rspack/core";
import { beforeAll, bench, describe } from "vitest";

const one = join(__dirname, "fixtures/vanilla-js/one.js");

let buildModule: Promise<void>;

function next() {

}

class LoaderBenchPlguin {
cb: () => void;

apply(compiler) {
const pluginName = this.constructor.name;

compiler.hooks.compilation.tap(pluginName, compilation => {
compilation.hooks.buildModule.tap(pluginName, module => {
if (module.resource == one) {
buildModule = new Promise(resolve => {
this.cb = resolve;
});
}
});

compilation.hooks.succeedModule.tap(pluginName, module => {
if (module.resource == one) {
}
});

compilation.hooks.failedModule.tap(pluginName, () => {
throw new Error("Module build failed");
});
});
}
}

beforeAll(() => {
return new Promise((resolve, reject) =>
rspack(
{
entry: one,
mode: "production",
plugins: [
new LoaderBenchPlguin()
]
},
(err, stats) => {
if (err) {
reject(err);
}
if (stats?.hasErrors()) {
reject(new Error(stats.toString({})));
}
resolve(undefined);
}
)
);
});

describe("Loader", () => {
bench("One", async () => {
await next();
});
});
2 changes: 2 additions & 0 deletions tests/bench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"@rspack/plugin-react-refresh": "1.0.0",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"tinybench": "2.9.0",
"vitest": "^2.1.8"
},
"dependencies": {
"@codspeed/tinybench-plugin": "^4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import codspeedPlugin from "@codspeed/vitest-plugin";
import { defineConfig } from "vitest/config";

export default defineConfig({
plugins: [codspeedPlugin()],
// plugins: [codspeedPlugin()],
test: {
fileParallelism: true
}
Expand Down

0 comments on commit 3ae02ec

Please sign in to comment.