Skip to content

Commit 7da01fb

Browse files
Add benchmark
1 parent 6e3ce5b commit 7da01fb

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"types": "dist/index.d.ts",
3131
"sideEffects": false,
3232
"scripts": {
33+
"bench": "npm run build && node test/benchmark.js",
3334
"build": "npm run clean && npm run build:node:cjs && npm run build:node:esm && npm run build:browser:cjs && npm run build:browser:esm && npm run build:types",
3435
"build:browser:cjs": "FMT=cjs ENV=browser rollup -c --name ulidx",
3536
"build:browser:esm": "FMT=esm ENV=browser rollup -c --name ulidx",
@@ -61,6 +62,7 @@
6162
"@rollup/plugin-node-resolve": "^16.0.1",
6263
"@rollup/plugin-typescript": "^12.1.2",
6364
"@types/node": "^22.13.10",
65+
"benchmark": "^2.1.4",
6466
"prettier": "^3.5.3",
6567
"rollup": "^4.36.0",
6668
"tslib": "^2.8.1",

test/benchmark.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Benchmark from "benchmark";
2+
import { ulid } from "../dist/node/index.js";
3+
4+
const suite = new Benchmark.Suite();
5+
6+
// add tests
7+
suite.add("Simple ulid", function () {
8+
ulid();
9+
});
10+
suite.add("ulid with timestamp", function () {
11+
ulid(Date.now());
12+
});
13+
14+
// add listeners
15+
suite.on("cycle", function (event) {
16+
console.log(String(event.target));
17+
});
18+
suite.on("complete", function () {
19+
console.log("Done!");
20+
});
21+
22+
// run async
23+
suite.run({ async: true });

0 commit comments

Comments
 (0)