Console: console.time()
Use console.time() and console.timeEnd() with the same label to measure elapsed time in the developer console.
What you will learn
- How to start and stop a labeled timer
- How to compare a small change while debugging
- Why console timing is a guide, not a complete benchmark
Basic example
console.time('load data');
loadData();
console.timeEnd('load data');The console reports the elapsed time between the two calls. The labels must match, and timers are local to the page's execution context.
Common mistakes
- Do not call
console.timeEnd()with a different label. - Run the same test more than once before drawing a conclusion.
- Use a production profiler or benchmark when accurate performance data matters.