Last active
April 21, 2022 13:36
-
-
Save mkuchak/62416bd449268fa6a72573027e962de3 to your computer and use it in GitHub Desktop.
Measure performance of NanoID and Web Crypto API to generate unique identifiers
This file contains hidden or 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
// run it on browser console | |
const { nanoid } = await import( | |
'https://cdnjs.cloudflare.com/ajax/libs/nanoid/3.3.2/nanoid.min.js' | |
) | |
const loops = 1_000_000 | |
console.time('NanoID') | |
for (let i = 0; i < loops; i++) { | |
nanoid() | |
} | |
console.timeEnd('NanoID') | |
console.time('WebCryptoUUID') | |
for (let i = 0; i < loops; i++) { | |
crypto.randomUUID() | |
} | |
console.timeEnd('WebCryptoUUID') | |
// Typical result: | |
// NanoID: 2849.41015625 ms | |
// WebCryptoUUID: 2215.301025390625 ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment