Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/watson/uuid-benchmark

Benchmark of different UUID generation methods in Node.js 🐢🚀
https://github.com/watson/uuid-benchmark

Last synced: about 1 month ago
JSON representation

Benchmark of different UUID generation methods in Node.js 🐢🚀

Awesome Lists containing this project

README

        

# Node.js UUID Benchmark 🐢🚀

The following benchmark results are generated on a MacBook (Early 2016)
with a 1,3 GHz Intel Core m7 processor using Node.js 10.8.0.

To run them your self, run:

```
npm run bench
```

_See raw results in [`results.csv`](results.csv)_

## 128 bit UUID

| Method | Features | Re-use | Sync | Cache | Format | Ops/sec | RME | Samples |
| :----------------------- | :------- | :----: | :--: | ----: | :----- | --------: | :----- | ------: |
| [uuid/v1] | 🌎 | | ✅ | | uuid | 1,031,720 | ±1.68% | 89 |
| [uuid/v1] | 🌎 | | ✅ | | hex | 402,318 | ±1.38% | 86 |
| [uuid/v1] | 🌎 | ✅ | ✅ | | hex | 544,231 | ±1.02% | 91 |
| [uuid/v1] | 🌎 | | ✅ | | buffer | 463,279 | ±2.10% | 84 |
| [uuid/v1] | 🌎 | ✅ | ✅ | | buffer | 625,377 | ±1.61% | 91 |
| [uuid/v4] | 🌎🔀🛡️ | | ✅ | | uuid | 242,402 | ±1.77% | 88 |
| [uuid/v4] | 🌎🔀🛡️ | | ✅ | | hex | 224,290 | ±3.78% | 81 |
| [uuid/v4] | 🌎🔀🛡️ | ✅ | ✅ | | hex | 261,648 | ±3.28% | 87 |
| [uuid/v4] | 🌎🔀🛡️ | | ✅ | | buffer | 248,587 | ±5.01% | 79 |
| [uuid/v4] | 🌎🔀🛡️ | ✅ | ✅ | | buffer | 293,626 | ±3.17% | 89 |
| [fast-uuid] | 🌎🔀 | | ✅ | | uuid | 647,364 | ±0.82% | 91 |
| [uuid-random] | 🌎🔀🛡️ | | ✅ | 512 | uuid | 1,249,273 | ±0.93% | 92 |
| [uuid-random] | 🌎🔀🛡️ | | ✅ | 512 | hex | 1,182,259 | ±0.92% | 92 |
| [uuid-random] | 🌎🔀🛡️ | | ✅ | 512 | buffer | 1,749,568 | ±0.94% | 91 |
| [sodium-uuid] | 🌎🔀🛡️ | | ✅ | | hex | 222,468 | ±0.74% | 85 |
| [sodium-uuid] | 🌎🔀🛡️ | ✅ | ✅ | | hex | 230,227 | ±0.97% | 90 |
| [sodium-uuid] | 🌎🔀🛡️ | | ✅ | | buffer | 282,921 | ±0.76% | 95 |
| [sodium-uuid] | 🌎🔀🛡️ | ✅ | ✅ | | buffer | 285,123 | ±0.79% | 91 |
| [sodium-native] | 🌎🔀🛡️ | | ✅ | | hex | 207,240 | ±1.85% | 92 |
| [sodium-native] | 🌎🔀🛡️ | ✅ | ✅ | | hex | 246,718 | ±1.20% | 93 |
| [sodium-native] | 🌎🔀🛡️ | | ✅ | | buffer | 218,728 | ±2.85% | 87 |
| [sodium-native] | 🌎🔀🛡️ | ✅ | ✅ | | buffer | 288,010 | ±0.76% | 95 |
| [sodium-native] | 🌎🔀🛡️ | | ✅ | 256 | hex | 487,380 | ±0.66% | 95 |
| [sodium-native] | 🌎🔀🛡️ | ✅ | ✅ | 256 | hex | 484,132 | ±0.69% | 89 |
| [sodium-native] | 🌎🔀🛡️ | | ✅ | 256 | buffer | 579,664 | ±0.59% | 87 |
| [sodium-native] | 🌎🔀🛡️ | ✅ | ✅ | 256 | buffer | 567,894 | ±0.72% | 86 |
| [sodium-native] | 🌎🔀🛡️ | | ✅ | 4096 | hex | 509,949 | ±4.29% | 85 |
| [sodium-native] | 🌎🔀🛡️ | ✅ | ✅ | 4096 | hex | 514,632 | ±0.95% | 92 |
| [sodium-native] | 🌎🔀🛡️ | | ✅ | 4096 | buffer | 589,869 | ±0.83% | 91 |
| [sodium-native] | 🌎🔀🛡️ | ✅ | ✅ | 4096 | buffer | 584,236 | ±0.59% | 93 |
| [sodium-native] | 🌎🔀🛡️ | | ✅ | 65536 | hex | 549,442 | ±0.98% | 27 |
| [sodium-native] | 🌎🔀🛡️ | ✅ | ✅ | 65536 | hex | 503,349 | ±0.76% | 81 |
| [sodium-native] | 🌎🔀🛡️ | | ✅ | 65536 | buffer | 592,077 | ±1.12% | 87 |
| [sodium-native] | 🌎🔀🛡️ | ✅ | ✅ | 65536 | buffer | 635,565 | ±0.92% | 18 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | | | hex | 36,611 | ±1.81% | 73 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | ✅ | | hex | 247,546 | ±2.87% | 87 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | | | buffer | 38,647 | ±1.39% | 76 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | ✅ | | buffer | 283,446 | ±2.93% | 88 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | ✅ | 256 | hex | 930,412 | ±1.40% | 88 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | ✅ | 256 | hex | 893,849 | ±1.18% | 91 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | | 256 | hex | 322,917 | ±1.66% | 76 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | | 256 | hex | 319,095 | ±1.52% | 74 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | ✅ | 256 | buffer | 1,263,214 | ±1.34% | 85 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | ✅ | 256 | buffer | 1,210,984 | ±2.24% | 85 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | | 256 | buffer | 374,283 | ±2.25% | 74 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | | 256 | buffer | 385,773 | ±1.32% | 72 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | ✅ | 4096 | hex | 1,213,789 | ±0.61% | 94 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | ✅ | 4096 | hex | 1,132,888 | ±1.04% | 90 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | | 4096 | hex | 798,433 | ±2.15% | 74 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | | 4096 | hex | 803,000 | ±1.31% | 78 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | ✅ | 4096 | buffer | 1,810,661 | ±1.08% | 89 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | ✅ | 4096 | buffer | 1,708,659 | ±1.13% | 93 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | | 4096 | buffer | 1,179,573 | ±1.65% | 73 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | | 4096 | buffer | 1,084,560 | ±1.86% | 74 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | ✅ | 65536 | hex | 1,238,794 | ±0.67% | 90 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | ✅ | 65536 | hex | 1,162,037 | ±0.68% | 91 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | | 65536 | hex | 937,338 | ±1.01% | 77 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | | 65536 | hex | 910,588 | ±1.20% | 75 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | ✅ | 65536 | buffer | 1,907,768 | ±0.93% | 84 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | ✅ | 65536 | buffer | 1,789,604 | ±0.58% | 90 |
| [crypto.randomBytes] | 🌎🔀🛡️ | | | 65536 | buffer | 1,359,017 | ±1.67% | 75 |
| [crypto.randomBytes] | 🌎🔀🛡️ | ✅ | | 65536 | buffer | 1,349,288 | ±1.19% | 77 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | ✅ | ✅ | | hex | 297,034 | ±3.03% | 91 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | ✅ | ✅ | | buffer | 352,826 | ±0.58% | 95 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | | ✅ | 256 | hex | 972,593 | ±2.21% | 89 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | ✅ | ✅ | 256 | hex | 1,003,555 | ±1.26% | 91 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | | ✅ | 256 | buffer | 1,533,437 | ±0.94% | 89 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | ✅ | ✅ | 256 | buffer | 1,498,401 | ±0.83% | 89 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | | ✅ | 4096 | hex | 1,299,413 | ±1.33% | 92 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | ✅ | ✅ | 4096 | hex | 1,277,688 | ±0.94% | 89 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | | ✅ | 4096 | buffer | 2,127,692 | ±1.18% | 90 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | ✅ | ✅ | 4096 | buffer | 2,030,611 | ±0.78% | 95 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | | ✅ | 65536 | hex | 1,411,415 | ±0.73% | 61 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | ✅ | ✅ | 65536 | hex | 1,351,733 | ±1.12% | 64 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | | ✅ | 65536 | buffer | 2,173,932 | ±0.94% | 91 |
| [crypto.randomFillSync] | 🌎🔀🛡️ | ✅ | ✅ | 65536 | buffer | 1,978,253 | ±1.79% | 89 |
| [crypto.randomFill] | 🌎🔀🛡️ | ✅ | | | hex | 35,753 | ±1.64% | 74 |
| [crypto.randomFill] | 🌎🔀🛡️ | ✅ | | | buffer | 40,443 | ±1.72% | 76 |
| [crypto.randomFill] | 🌎🔀🛡️ | | | 256 | hex | 337,253 | ±1.89% | 69 |
| [crypto.randomFill] | 🌎🔀🛡️ | ✅ | | 256 | hex | 342,601 | ±1.53% | 74 |
| [crypto.randomFill] | 🌎🔀🛡️ | | | 256 | buffer | 394,036 | ±1.80% | 73 |
| [crypto.randomFill] | 🌎🔀🛡️ | ✅ | | 256 | buffer | 398,759 | ±1.55% | 73 |
| [crypto.randomFill] | 🌎🔀🛡️ | | | 4096 | hex | 838,637 | ±1.58% | 75 |
| [crypto.randomFill] | 🌎🔀🛡️ | ✅ | | 4096 | hex | 795,834 | ±1.19% | 77 |
| [crypto.randomFill] | 🌎🔀🛡️ | | | 4096 | buffer | 1,099,979 | ±4.33% | 73 |
| [crypto.randomFill] | 🌎🔀🛡️ | ✅ | | 4096 | buffer | 1,124,590 | ±1.94% | 72 |
| [crypto.randomFill] | 🌎🔀🛡️ | | | 65536 | hex | 910,602 | ±1.70% | 77 |
| [crypto.randomFill] | 🌎🔀🛡️ | ✅ | | 65536 | hex | 899,567 | ±1.12% | 78 |
| [crypto.randomFill] | 🌎🔀🛡️ | | | 65536 | buffer | 1,379,134 | ±1.24% | 77 |
| [crypto.randomFill] | 🌎🔀🛡️ | ✅ | | 65536 | buffer | 1,356,052 | ±1.10% | 74 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | | | hex | 40,092 | ±1.67% | 73 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | ✅ | | hex | 226,814 | ±0.46% | 96 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | | | buffer | 41,103 | ±2.07% | 76 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | ✅ | | buffer | 262,087 | ±0.66% | 93 |
| [/dev/random] | 🌎🔀🛡️ | | | 256 | hex | 234,066 | ±1.29% | 77 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | | 256 | hex | 235,687 | ±1.66% | 75 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | ✅ | 256 | hex | 443,135 | ±0.88% | 88 |
| [/dev/random] | 🌎🔀🛡️ | | | 256 | buffer | 269,161 | ±1.50% | 72 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | | 256 | buffer | 267,478 | ±1.62% | 72 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | ✅ | 256 | buffer | 525,963 | ±0.59% | 92 |
| [/dev/random] | 🌎🔀🛡️ | | | 4096 | hex | 381,099 | ±1.53% | 77 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | | 4096 | hex | 388,474 | ±1.50% | 77 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | ✅ | 4096 | hex | 491,756 | ±0.60% | 93 |
| [/dev/random] | 🌎🔀🛡️ | | | 4096 | buffer | 454,175 | ±1.28% | 76 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | | 4096 | buffer | 448,020 | ±1.31% | 77 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | ✅ | 4096 | buffer | 574,020 | ±0.64% | 94 |
| [/dev/random] | 🌎🔀🛡️ | | | 65536 | hex | 409,728 | ±1.48% | 75 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | | 65536 | hex | 450,289 | ±1.31% | 50 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | ✅ | 65536 | hex | 541,220 | ±1.04% | 31 |
| [/dev/random] | 🌎🔀🛡️ | | | 65536 | buffer | 483,239 | ±1.34% | 74 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | | 65536 | buffer | 525,563 | ±1.42% | 49 |
| [/dev/random] | 🌎🔀🛡️ | ✅ | ✅ | 65536 | buffer | 636,141 | ±0.76% | 19 |
| [/dev/urandom] | 🌎🔀 | ✅ | | | hex | 39,507 | ±1.28% | 76 |
| [/dev/urandom] | 🌎🔀 | ✅ | ✅ | | hex | 225,501 | ±1.16% | 96 |
| [/dev/urandom] | 🌎🔀 | ✅ | | | buffer | 42,675 | ±1.60% | 75 |
| [/dev/urandom] | 🌎🔀 | ✅ | ✅ | | buffer | 262,925 | ±0.53% | 96 |
| [/dev/urandom] | 🌎🔀 | | | 256 | hex | 242,490 | ±1.25% | 76 |
| [/dev/urandom] | 🌎🔀 | ✅ | | 256 | hex | 247,783 | ±1.28% | 74 |
| [/dev/urandom] | 🌎🔀 | ✅ | ✅ | 256 | hex | 449,219 | ±0.57% | 95 |
| [/dev/urandom] | 🌎🔀 | | | 256 | buffer | 260,615 | ±1.44% | 73 |
| [/dev/urandom] | 🌎🔀 | ✅ | | 256 | buffer | 268,182 | ±1.63% | 74 |
| [/dev/urandom] | 🌎🔀 | ✅ | ✅ | 256 | buffer | 529,952 | ±0.34% | 91 |
| [/dev/urandom] | 🌎🔀 | | | 4096 | hex | 393,407 | ±1.38% | 73 |
| [/dev/urandom] | 🌎🔀 | ✅ | | 4096 | hex | 386,528 | ±1.07% | 78 |
| [/dev/urandom] | 🌎🔀 | ✅ | ✅ | 4096 | hex | 489,407 | ±0.71% | 92 |
| [/dev/urandom] | 🌎🔀 | | | 4096 | buffer | 450,002 | ±1.35% | 73 |
| [/dev/urandom] | 🌎🔀 | ✅ | | 4096 | buffer | 446,349 | ±1.50% | 78 |
| [/dev/urandom] | 🌎🔀 | ✅ | ✅ | 4096 | buffer | 573,550 | ±0.72% | 91 |
| [/dev/urandom] | 🌎🔀 | | | 65536 | hex | 416,024 | ±1.48% | 76 |
| [/dev/urandom] | 🌎🔀 | ✅ | | 65536 | hex | 445,563 | ±1.30% | 51 |
| [/dev/urandom] | 🌎🔀 | ✅ | ✅ | 65536 | hex | 539,710 | ±0.82% | 32 |
| [/dev/urandom] | 🌎🔀 | | | 65536 | buffer | 492,679 | ±1.67% | 71 |
| [/dev/urandom] | 🌎🔀 | ✅ | | 65536 | buffer | 479,059 | ±1.36% | 74 |
| [/dev/urandom] | 🌎🔀 | ✅ | ✅ | 65536 | buffer | 637,976 | ±0.65% | 20 |

## Non UUID

The following ID generators does not generate 128 bit id's. Beware that
not all of them are globally unique.

| Method | Features | Re-use | Sync | Cache | Ops/sec | RME | Samples | Example |
| :------------------- | :------- | :----: | :--: | ----: | --------: | :----- | ------: | :---------------------------------------------- |
| [hyperid] cold start | 🌎 | | ✅ | | 102,478 | ±1.01% | 89 | PK9867v+RGmX2kdtHbPe1g/0 |
| [hyperid] normal | 🌎 | | ✅ | | 8,495,558 | ±2.28% | 83 | PK9867v+RGmX2kdtHbPe1g/0 |
| [cuid] | 🌎 | | ✅ | | 448,945 | ±0.66% | 88 | cjksp2h270000e8hgvs5t9ihj |
| [shortid] | 🔀 | | ✅ | | 22,552 | ±3.58% | 81 | p300jY3TE |
| [nanoid] | 🌎🔀🛡️ | | ✅ | | 237,373 | ±1.36% | 86 | 2nlN~BJaTgdWQm01WS2uG |

## Legend

- **Method:** Name of npm module, Node.js core function, or OS based random generator used
- **Features:**
- 🌎 (GUID) - The ID is globally unique
- 🛡 (Secure) - The method used to generate the ID doesn't leak metadata and it's not possible to predict what the next ID will be
- 🔀 (Random) - The ID is made up of random data
- **Re-use:** An output buffer was re-used between each test to potentially reduce the number of objects that needed to be allocated
- **Sync:** The ID generation was performed synchronously
- **Cache:**
- <empty> - Only the amount of bytes required to generate a 128 bit number was read into memory
- <Number> - Number of bytes read into memory the first time a 128 bit number was requested. Subsequent runs would use the leftover bytes in the cache until it had been depleted, at which time another chunk of bytes would be read into memory
- **Format:**
- `uuid` - ID is a UUID formatted string representing a 128 bit number, e.g. `3a017fc5-4f50-4db9-b0ce-4547ba0a1bfd`
- `hex` - ID is a hex formatted string representing a 128 bit number, e.g. `3a017fc54f504db9b0ce4547ba0a1bfd`
- `buffer` - ID is a raw 128 bit binary Buffer object
- `other` - ID is **not** a UUID or 128 bit number, and might not be globally unique
- **Ops/sec:** Number of ID's generated per second
- **RME:** The relative margin of error (expressed as a percentage of the mean)
- **Samples:** Number of runs sampled
- **Example:** Example of a generated ID

## License

[MIT](LICENSE)

[uuid/v1]: https://www.npmjs.com/package/uuid
[uuid/v4]: https://www.npmjs.com/package/uuid
[fast-uuid]: https://www.npmjs.com/package/fast-uuid
[uuid-random]: https://www.npmjs.com/package/uuid-random
[sodium-uuid]: https://www.npmjs.com/package/sodium-uuid
[sodium-native]: https://www.npmjs.com/package/sodium-native
[crypto.randomBytes]: https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback
[crypto.randomFillSync]: https://nodejs.org/api/crypto.html#crypto_crypto_randomfillsync_buffer_offset_size
[crypto.randomFill]: https://nodejs.org/api/crypto.html#crypto_crypto_randomfill_buffer_offset_size_callback
[/dev/random]: https://en.wikipedia.org/wiki//dev/random
[/dev/urandom]: https://en.wikipedia.org/wiki//dev/random
[hyperid]: https://www.npmjs.com/package/hyperid
[cuid]: https://www.npmjs.com/package/cuid
[shortid]: https://www.npmjs.com/package/shortid
[nanoid]: https://www.npmjs.com/package/nanoid