Skip to content

Commit b53de70

Browse files
committed
chore: new bench
1 parent 0bf8fdd commit b53de70

File tree

4 files changed

+50
-310
lines changed

4 files changed

+50
-310
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"dist"
2323
],
2424
"scripts": {
25-
"benchmark": "vitest bench",
25+
"bench": "node --expose-gc --allow-natives-syntax test/bench.ts",
2626
"build": "obuild src/index.ts",
2727
"dev": "vitest",
2828
"lint": "eslint --cache . && prettier -c src test",
@@ -40,6 +40,8 @@
4040
"eslint": "^9.38.0",
4141
"eslint-config-unjs": "^0.5.0",
4242
"expect-type": "^1.2.2",
43+
"hookable-prev": "npm:hookable@^5.0.0",
44+
"mitata": "^1.0.34",
4345
"obuild": "^0.3.0",
4446
"prettier": "^3.6.2",
4547
"typescript": "^5.9.3",

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/bench.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { bench, compact, summary, run, do_not_optimize } from "mitata";
2+
import { Hookable, HookableCore } from "../src/hookable.ts";
3+
import { Hookable as HookablePrev } from "hookable-prev";
4+
5+
const instances = {
6+
hookable: new Hookable(),
7+
hookableCore: new HookableCore(),
8+
hookablePrev: new HookablePrev(),
9+
} as const;
10+
11+
for (const instance of Object.values(instances)) {
12+
instance.hook("test", (obj) => {
13+
obj.called = true;
14+
});
15+
}
16+
17+
summary(() => {
18+
compact(() => {
19+
bench("Hookable", () =>
20+
do_not_optimize(instances.hookable.callHook("test", {})),
21+
);
22+
bench("HookableCore", () =>
23+
do_not_optimize(instances.hookableCore.callHook("test", {})),
24+
);
25+
bench("HookablePrev", () =>
26+
do_not_optimize(instances.hookablePrev.callHook("test", {})),
27+
);
28+
});
29+
});
30+
31+
await run({ throw: true });

0 commit comments

Comments
 (0)