Closed Compositr closed 1 year ago
Date.now()
was added to the ECMAScript spec in ES5. The original CUID implementation predates ES5's widespread availability by 2-3 years.
The slow path takes 100 - 120ms to calculate 1 million dates. The fast path takes 90 - 110ms. This is a tiny micro-optimization. You'd need to be generating hundreds of thousands of CUIDs in a tight loop (like a render loop) for this to make any notable impact with users. Is this actually a bottleneck for you, and if so, in what situation?
I'm going to close this issue for now. Feel free to re-open if this is actually causing a problem for you.
On line 42 the timestamp generated by creating a new
Date
instance and calling thegetTime
method on it.However, as shown by this benchmark,
Date.now
is ~15% faster than creating a newDate
instance. Is there any specific reason to not use Date.now?