Created
June 26, 2024 10:31
-
-
Save remorses/033bfdc9e226f3f8f55491905231012e to your computer and use it in GitHub Desktop.
Cuid2 is very slow, don't use it
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
import { createId } from '@paralleldrive/cuid2' | |
import { v7, v4 } from 'uuid' | |
function cuid() { | |
let n = 1_000_000 | |
let list = [] as string[] | |
let start = Date.now() | |
for (let i = 0; i < n; i++) { | |
let id = createId() | |
list.push(id) | |
} | |
let end = Date.now() | |
console.log(`Generated ${n} ids in ${end - start}ms`) | |
} | |
function goodId() { | |
let n = 1_000_000 | |
let list = [] as string[] | |
let start = Date.now() | |
for (let i = 0; i < n; i++) { | |
let id = v4() | |
list.push(id) | |
} | |
let end = Date.now() | |
console.log(`Generated ${n} ids in ${end - start}ms`) | |
} | |
goodId() | |
goodId() | |
goodId() | |
cuid() | |
cuid() | |
cuid() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment