JavaScript · Senior · Question 28 of 75
Why is performance.now() better than Date.now() for measuring execution time?
- ✓Correct answer: It's a precise monotonic timer independent of the system clock
- 2It returns the exact server time rather than the user's clock
- 3It runs outside the event loop and can't be slowed by load
Explanation
Date.now() is milliseconds by the system clock, which can shift (sync, time changes). performance.now() counts from the start of navigation with fractional milliseconds. For marks in DevTools there are performance.mark() and measure().