Skip to content

ulid() slow vs monotonic #126

@atlanteh

Description

@atlanteh

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions