Skip to content

Commit

Permalink
Updated benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Dec 15, 2020
1 parent 28bb2d7 commit d9d1a1b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ Uber-fast unique id generation, for Node.js and the browser.
Here are the benchmarks:

```
hashids process.hrtime x 282,674 ops/sec ±0.87% (95 runs sampled)
hashids counter x 561,497 ops/sec ±0.30% (98 runs sampled)
shortid x 44,641 ops/sec ±0.45% (93 runs sampled)
nid x 1,438,733 ops/sec ±0.50% (96 runs sampled)
uuid.v4 x 390,607 ops/sec ±0.24% (92 runs sampled)
uuid.v1 x 1,725,443 ops/sec ±0.11% (98 runs sampled)
hyperid - variable length x 14,534,944 ops/sec ±0.80% (93 runs sampled)
hyperid - fixed length x 14,452,901 ops/sec ±0.48% (94 runs sampled)
hashids process.hrtime x 287,412 ops/sec ±0.99% (90 runs sampled)
hashids counter x 621,430 ops/sec ±0.29% (97 runs sampled)
shortid x 41,179 ops/sec ±0.42% (90 runs sampled)
crypto.random x 383,473 ops/sec ±1.32% (90 runs sampled)
nid x 1,451,918 ops/sec ±0.23% (96 runs sampled)
uuid.v4 x 381,392 ops/sec ±0.46% (90 runs sampled)
uuid.v1 x 1,904,561 ops/sec ±0.31% (96 runs sampled)
nanoid x 2,137,111 ops/sec ±0.31% (95 runs sampled)
hyperid - variable length x 15,252,339 ops/sec ±0.79% (88 runs sampled)
hyperid - fixed length x 15,029,819 ops/sec ±0.63% (93 runs sampled)
hyperid - fixed length, url safe x 15,449,475 ops/sec ±0.49% (93 runs sampled)
```

_Note:_ Benchmark run with Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz and Node.js v12.14.2
_Note:_ Benchmark run with Intel(R) Core(TM) i7-7700 CPU @ 3.60GHz and Node.js v14.15.1

## Install

Expand Down Expand Up @@ -44,15 +47,15 @@ console.log(hyperid.decode(instance()))

### hyperid([fixedLength || options])

Returns a function to generate unique ids.
Returns a function to generate unique ids.
The function can accept one of the following parameters:
- `fixedLength: Boolean`
- `fixedLength: Boolean`
If *fixedLength* is `true` the function will always generate an id
that is 33 characters in length, by default `fixedLength` is `false`.
- `options: Object`
that is 33 characters in length, by default `fixedLength` is `false`.
- `options: Object`
If `{ fixedLength: true }` is passed in, the function will always generate an id
that is 33 characters in length, by default `fixedLength` is `false`.
If `{ urlSafe: true }` is passed in, the function will generate url safe ids.
that is 33 characters in length, by default `fixedLength` is `false`.
If `{ urlSafe: true }` is passed in, the function will generate url safe ids.
If `{ startFrom: <int> }` is passed in, the first counter will start from that
number, which must be between 0 and 2147483647. Fractions are discarded, only the
integer part matters.
Expand All @@ -69,8 +72,8 @@ It is regenerated every `Math.pow(2, 31) - 1` to keep the integer a SMI

### hyperid.decode(id, [options])

Decode the unique id into its two components, a `uuid` and a counter.
If you are generating *url safe* ids, you must pass `{ urlSafe: true }` as option.
Decode the unique id into its two components, a `uuid` and a counter.
If you are generating *url safe* ids, you must pass `{ urlSafe: true }` as option.
It returns:

```js
Expand Down
5 changes: 5 additions & 0 deletions benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const shortid = require('shortid')
const nid = require('nid')
const crypto = require('crypto')
const uuid = require('uuid')
const { nanoid } = require('nanoid')
const hyperid = require('.')

const hyperIdSafeUrlInstance = hyperid({
Expand Down Expand Up @@ -47,6 +48,10 @@ suite.add('uuid.v1', function () {
uuid.v1()
})

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

suite.add('hyperid - variable length', function () {
hyperIdInstance()
})
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"benchmark": "^2.1.4",
"bloomfilter": "0.0.18",
"hashids": "^1.2.2",
"nanoid": "^3.1.20",
"nid": "^1.1.0",
"pre-commit": "^1.2.2",
"shortid": "^2.2.15",
Expand Down

0 comments on commit d9d1a1b

Please sign in to comment.