CodePark/ questions / Measuring performance
START PRACTICINGPRACTICE
Frontend question · Browser & web performance › Measuring performance

Why use performance.now() instead of Date.now() to time code?

It is high-resolution and monotonic, so it isn't affected by system clock changes

performance.now() is high-resolution and monotonic. Monotonic means it only moves forward. It returns milliseconds since the page's time origin, with precision finer than one millisecond. Date.now() follows the system clock, and that clock can jump if someone or something adjusts it.

"It measures CPU time instead of elapsed time" is the tempting wrong answer. Both functions measure elapsed (wall-clock) time, not CPU time. It doesn't return a readable date, and it doesn't send anything to the Performance panel.