THE WORLD'S LARGEST WEB DEVELOPER SITE

HTML DOM console.timeEnd() Method

❮ Console Object

Example

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

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

Definition and Usage

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

This method allows you to time certain operations in your code for testing purposes.

Use the console.time() method to start the timer.

Use the label parameter to specify which timer to end.

Tip: When testing console methods, be sure to have the console view visible (press F12 to view the console).


Browser Support

The numbers in the table specify the first browser version that fully supports the method.

Method
console.timeEnd() Yes 11 10 4 Yes

Syntax

console.timeEnd(label)

Parameter Values

Parameter Type Description
label String Optional. The name of the timer to end

More Examples

Example

Using the label parameter:

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

Example

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

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

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

❮ Console Object