Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

console.time

Measures how long code took to run.

Available since: Web API

Syntax

console.time(label) … console.timeEnd(label)

Parameters

ParameterTypeDescription
labelstringOptional. The timer name; timeEnd must use the same one.

Return value

undefinedReturns nothing.

Examples

Timing a loop (output in the browser console):

console.time('loop');
 
let sum = 0;
for (let i = 0; i < 1_000_000; i++) sum += i;
 
console.timeEnd('loop');

Output:

loop: 3.27 ms

Notes

The time differs on every run. console.timeLog(label) prints the intermediate time without stopping the timer. To measure in code use performance.now() or Date.now().

See also

  • Date.now — Returns the current time as a number of milliseconds.
  • console.count — Counts how many times this line was called.

Related recipes

In the tutorial

  • Debugging — How to find bugs in JavaScript: reading the error message, console.log and its variants, checking types, developer tools and debugger.

Thanks for reading!

Donate to the site — we work hard for you.