Javascript Measure Runtime Performance Link to heading
You can use the performance
API
const startTime = performance.now();
list.forEach(doExpensiveWork);
const endTime = performance.now() - startTime;
The time is in ms, to make it more human friendly:
function getElapsedTime(elapsedTime: number) {
if (elapsedTime < 1000) {
return `${elapsedTime.toFixed(3)} ms`;
}
if (elapsedTime < 60000) {
return `${(elapsedTime / 1000).toFixed(2)} s`;
}
return `${(elapsedTime / 60000).toFixed(2)} m`;
}