Skip to content

Commit

Permalink
Add fastest and slowest to benchmark
Browse files Browse the repository at this point in the history
- Add fastest and slowest to benchmarks
- upgrade packages
  • Loading branch information
woss committed Apr 13, 2024
1 parent 60204ad commit b78a7bb
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 84 deletions.
152 changes: 78 additions & 74 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,87 @@
'use strict'

const benchmark = require('benchmark')
const Hashids = require('hashids')
const shortid = require('shortid')
const nid = require('nid')
const crypto = require('crypto')
const uuid = require('uuid')
const { nanoid } = require('nanoid')
const hyperid = require('.')
const napiRsUuid = require('@napi-rs/uuid').v4
"use strict";

const benchmark = require("benchmark");
const Hashids = require("hashids");
const shortid = require("shortid");
const nid = require("nid");
const crypto = require("crypto");
const uuid = require("uuid");
const { nanoid } = require("nanoid");
const hyperid = require(".");
const napiRsUuid = require("@napi-rs/uuid").v4;

const hyperIdSafeUrlInstance = hyperid({
urlSafe: true
})
const hyperIdInstance = hyperid()
urlSafe: true,
});
const hyperIdInstance = hyperid();

const suite = new benchmark.Suite()
const suite = new benchmark.Suite();

const hashids = new Hashids('mybench')
const hashids = new Hashids("mybench");

if (crypto.randomUUID) {
suite.add('crypto.randomUUID', function () {
crypto.randomUUID()
})
suite.add("crypto.randomUUID", function () {
crypto.randomUUID();
});
}

suite.add('hashids process.hrtime', function () {
hashids.encode(process.hrtime())
})

let hashIdCounter = 0

suite.add('hashids counter', function () {
hashids.encode(hashIdCounter++)
})

suite.add('shortid', function () {
shortid()
})

suite.add('crypto.random', function () {
crypto.randomBytes(33).toString('hex')
})

suite.add('nid', function () {
nid()
})

suite.add('uuid.v4', function () {
uuid.v4()
})

suite.add('napiRsUuid.v4', function () {
napiRsUuid()
})

suite.add('uuid.v1', function () {
uuid.v1()
})

suite.add('nanoid', function () {
nanoid()
})

suite.add('hyperid - variable length', function () {
hyperIdInstance()
})

suite.add('hyperid - fixed length', function () {
hyperIdInstance(true)
})
suite.add('hyperid - fixed length, url safe', function () {
hyperIdSafeUrlInstance(true)
})

suite.on('cycle', cycle)

suite.run()

function cycle (e) {
console.log(e.target.toString())
suite.add("hashids process.hrtime", function () {
hashids.encode(process.hrtime());
});

let hashIdCounter = 0;

suite.add("hashids counter", function () {
hashids.encode(hashIdCounter++);
});

suite.add("shortid", function () {
shortid();
});

suite.add("crypto.random", function () {
crypto.randomBytes(33).toString("hex");
});

suite.add("nid", function () {
nid();
});

suite.add("uuid.v4", function () {
uuid.v4();
});

suite.add("napiRsUuid.v4", function () {
napiRsUuid();
});

suite.add("uuid.v1", function () {
uuid.v1();
});

suite.add("nanoid", function () {
nanoid();
});

suite.add("hyperid - variable length", function () {
hyperIdInstance();
});

suite.add("hyperid - fixed length", function () {
hyperIdInstance(true);
});
suite.add("hyperid - fixed length, url safe", function () {
hyperIdSafeUrlInstance(true);
});

suite.on("cycle", cycle);
suite.on("complete", function () {
console.log("\n");
console.log("Fastest is " + this.filter("fastest").map("name"));
console.log("Slowest is " + this.filter("slowest").map("name"));
});
suite.run({ await: true });

function cycle(e) {
console.log(e.target.toString());
}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@
},
"homepage": "https://github.com/mcollina/hyperid#readme",
"devDependencies": {
"@napi-rs/uuid": "^0.1.0",
"@napi-rs/uuid": "^0.2.0",
"benchmark": "^2.1.4",
"bloomfilter": "0.0.18",
"bloomfilter": "^0.0.18",
"hashids": "^2.2.8",
"nanoid": "^3.1.20",
"nid": "^1.1.0",
"nanoid": "^3.0.0",
"nid": "^2.0.1",
"pre-commit": "^1.2.2",
"shortid": "^2.2.15",
"standard": "^16.0.3",
"proxyquire": "^2.1.3",
"shortid": "^2.2.16",
"standard": "^17.1.0",
"tap-dot": "^2.0.0",
"tape": "^5.0.0",
"typescript": "^4.3.4",
"proxyquire": "^2.1.3"
"typescript": "^5.4.5"
},
"dependencies": {
"buffer": "^5.2.1",
"uuid": "^8.3.2",
"uuid-parse": "^1.1.0",
"buffer": "^5.2.1"
"uuid-parse": "^1.1.0"
},
"browser": {
"./uuid-node.js": "./uuid-browser.js"
Expand Down

0 comments on commit b78a7bb

Please sign in to comment.