Console timeEnd()

Example

How long does it take to perform a for-loop 100.000 times:

console.time();
for (let i = 0; i < 100000; i++) {
  // some code
}
console.timeEnd();
Try it Yourself »

More examples below.


Description

The timeEnd() method ends a timer, and writes the result to the console.

The timeEnd() method allows you to time code operations for testing purposes.

Note

You can run many timers at the same time.

Use the label parameter to name different timers.

See Also:

The console.time() Method.


Syntax

console.timeEnd(label)

Parameters

Parameter Description
label Optional.
The name of the timer.


More Examples

Using the label parameter:

console.time("test1");
for (let i = 0; i < 100000; i++) {
  // some code
}
console.timeEnd("test1");
Try it Yourself »

Which is fastest, the for loop or the while loop?

console.time("for loop");
for (let i = 0; i < 100000; i++) {
  // some code
}
console.timeEnd("for loop");

let i = 0;
console.time("while loop");
while (i < 1000000) {
  i++
}
console.timeEnd("while loop");
Try it Yourself »

Browser Support

console.timeEnd() is supported in all modern browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 11


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.