@codspeed/tinybench-plugin 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.es5.js +1 -1
- package/package.json +9 -6
package/README.md
CHANGED
|
@@ -1,6 +1,94 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1><code>@codspeed/tinybench</code></h1>
|
|
2
|
+
<h1><code>@codspeed/tinybench-plugin</code></h1>
|
|
3
3
|
|
|
4
4
|
tinybench compatibility layer for CodSpeed
|
|
5
5
|
|
|
6
|
+
[](https://github.com/CodSpeedHQ/codspeed-node/actions/workflows/ci.yml)
|
|
7
|
+
[](https://www.npmjs.com/package/@codspeed/tinybench-plugin)
|
|
8
|
+
[](https://discord.com/invite/MxpaCfKSqF)
|
|
9
|
+
|
|
6
10
|
</div>
|
|
11
|
+
|
|
12
|
+
## Documentation
|
|
13
|
+
|
|
14
|
+
Check out the [documentation](https://docs.codspeed.io/benchmarks/nodejs) for complete integration instructions.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
First install the plugin [`@codspeed/tinybench-plugin`](https://www.npmjs.com/package/@codspeed/tinybench-plugin) and `tinybench` (if not already installed):
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
npm install --save-dev @codspeed/tinybench-plugin tinybench
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
or with `yarn`:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
yarn add --dev @codspeed/tinybench-plugin tinybench
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
or with `pnpm`:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
pnpm add --save-dev @codspeed/tinybench-plugin tinybench
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
Let's create a fibonacci function and benchmark it with tinybench and the CodSpeed plugin:
|
|
39
|
+
|
|
40
|
+
```js title="benches/bench.mjs"
|
|
41
|
+
import { Bench } from "tinybench";
|
|
42
|
+
import { withCodSpeed } from "@codspeed/tinybench-plugin";
|
|
43
|
+
|
|
44
|
+
function fibonacci(n) {
|
|
45
|
+
if (n < 2) {
|
|
46
|
+
return n;
|
|
47
|
+
}
|
|
48
|
+
return fibonacci(n - 1) + fibonacci(n - 2);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const bench = withCodSpeed(new Bench());
|
|
52
|
+
|
|
53
|
+
bench
|
|
54
|
+
.add("fibonacci10", () => {
|
|
55
|
+
fibonacci(10);
|
|
56
|
+
})
|
|
57
|
+
.add("fibonacci15", () => {
|
|
58
|
+
fibonacci(15);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await bench.run();
|
|
62
|
+
console.table(
|
|
63
|
+
bench.tasks.map(({ name, result }) => ({
|
|
64
|
+
"Task Name": name,
|
|
65
|
+
"Average Time (ps)": result?.mean * 1000,
|
|
66
|
+
}))
|
|
67
|
+
);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Here, a few things are happening:
|
|
71
|
+
|
|
72
|
+
- We create a simple recursive fibonacci function.
|
|
73
|
+
- We create a new `Bench` instance with CodSpeed support by using the **`withCodSpeed`** helper. This step is **critical** to enable CodSpeed on your benchmarks.
|
|
74
|
+
|
|
75
|
+
- We add two benchmarks to the suite and launch it, benching our `fibonacci` function for 10 and 15.
|
|
76
|
+
|
|
77
|
+
Now, we can run our benchmarks locally to make sure everything is working as expected:
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
$ node benches/bench.mjs
|
|
81
|
+
[CodSpeed] 2 benches detected but no instrumentation found
|
|
82
|
+
[CodSpeed] falling back to tinybench
|
|
83
|
+
|
|
84
|
+
┌─────────┬───────────────┬────────────────────┐
|
|
85
|
+
│ (index) │ Task Name │ Average Time (ps) │
|
|
86
|
+
├─────────┼───────────────┼────────────────────┤
|
|
87
|
+
│ 0 │ 'fibonacci10' │ 0.5660083779532603 │
|
|
88
|
+
│ 1 │ 'fibonacci15' │ 5.2475729101797635 │
|
|
89
|
+
└─────────┴───────────────┴────────────────────┘
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
And... Congrats🎉, CodSpeed is installed in your benchmarking suite! Locally, CodSpeed will fallback to tinybench since the instrumentation is only available in the CI environment for now.
|
|
93
|
+
|
|
94
|
+
You can now [run those benchmark in your CI](https://docs.codspeed.io/benchmarks/nodejs#running-the-benchmarks-in-your-ci) to continuously get consistent performance measurements.
|
package/dist/index.cjs.js
CHANGED
|
@@ -172,7 +172,7 @@ function withCodSpeed(bench) {
|
|
|
172
172
|
core.initCore();
|
|
173
173
|
const callingFile = getCallingFile();
|
|
174
174
|
bench.run = async () => {
|
|
175
|
-
console.log(`[CodSpeed] running with @codspeed/tinybench v${"1.0.
|
|
175
|
+
console.log(`[CodSpeed] running with @codspeed/tinybench v${"1.0.2"}`);
|
|
176
176
|
for (const task of bench.tasks) {
|
|
177
177
|
const uri = callingFile + "::" + task.name;
|
|
178
178
|
await core.optimizeFunction(task.fn);
|
package/dist/index.es5.js
CHANGED
|
@@ -170,7 +170,7 @@ function withCodSpeed(bench) {
|
|
|
170
170
|
initCore();
|
|
171
171
|
const callingFile = getCallingFile();
|
|
172
172
|
bench.run = async () => {
|
|
173
|
-
console.log(`[CodSpeed] running with @codspeed/tinybench v${"1.0.
|
|
173
|
+
console.log(`[CodSpeed] running with @codspeed/tinybench v${"1.0.2"}`);
|
|
174
174
|
for (const task of bench.tasks) {
|
|
175
175
|
const uri = callingFile + "::" + task.name;
|
|
176
176
|
await optimizeFunction(task.fn);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codspeed/tinybench-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "tinybench compatibility layer for CodSpeed",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codspeed",
|
|
@@ -15,18 +15,21 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"author": "Arthur Pastel <arthur@codspeed.io>",
|
|
18
|
-
"repository": "https://github.com/CodSpeedHQ/codspeed-node
|
|
18
|
+
"repository": "https://github.com/CodSpeedHQ/codspeed-node",
|
|
19
19
|
"homepage": "https://codspeed.io",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/find-up": "^4.0.0",
|
|
23
23
|
"@types/stack-trace": "^0.0.30",
|
|
24
|
-
"jest-mock-extended": "^3.0.1"
|
|
24
|
+
"jest-mock-extended": "^3.0.1",
|
|
25
|
+
"tinybench": "^2.3.0"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
|
-
"@codspeed/core": "^1.0.
|
|
28
|
+
"@codspeed/core": "^1.0.2",
|
|
28
29
|
"find-up": "^6.3.0",
|
|
29
|
-
"stack-trace": "1.0.0-pre1"
|
|
30
|
-
|
|
30
|
+
"stack-trace": "1.0.0-pre1"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"tinybench": "^2.3.0"
|
|
31
34
|
}
|
|
32
35
|
}
|