-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fastest and slowest to benchmark
- Add fastest and slowest to benchmarks - upgrade packages
- Loading branch information
Showing
2 changed files
with
88 additions
and
84 deletions.
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 |
---|---|---|
@@ -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()); | ||
} |
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