Skip to content

Instantly share code, notes, and snippets.

@remorses
Created June 26, 2024 10:31
Show Gist options
  • Save remorses/033bfdc9e226f3f8f55491905231012e to your computer and use it in GitHub Desktop.
Save remorses/033bfdc9e226f3f8f55491905231012e to your computer and use it in GitHub Desktop.
Cuid2 is very slow, don't use it
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