-
-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log("one"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters