-
Notifications
You must be signed in to change notification settings - Fork 111
Open
Description
Does it make sense that ulid() is so slow relative to monothonic?
I ran this simple benchmark multiple times to test this library vs uuidv7, and it always returns around the same results:
import { ulid, monotonicFactory } from 'ulid';
function bench(name, fn, N = 5_000_000) {
// warmup
for (let i = 0; i < 200_000; i++) fn();
const t0 = performance.now();
for (let i = 0; i < N; i++) fn();
const t1 = performance.now();
console.log(`${name}: ${(N / ((t1 - t0) / 1000)).toFixed(1)} ids/sec`);
}
bench('uuidv7', uuidv7);
bench('ulid', ulid);
bench('ulid(monotonic)', monotonicFactory());
The results
uuidv7: 5486105.0 ids/sec
ulid: 31140.8 ids/sec
ulid(monotonic): 2054127.8 ids/sec
why is ulid() much slower than monotonic? and why is monotonic slower than uuidv7?
Metadata
Metadata
Assignees
Labels
No labels