Skip to content

performance.now()

performance.now() returns a DOMHighResTimeStamp measured in milliseconds and is useful to calculate how long a function take.

Usage:

js
const t0 = performance.now();
doSomething();
const t1 = performance.now();
console.log(`Call to doSomething took ${t1 - t0} milliseconds.`); // Call to doSomething took 1.2 milliseconds.

This is especially useful for testing and optimizing the performance of specific functions.