HTML DOM console.timeEnd()Method
Examples
Actual time taken for 100,000 executions:
console.time();
for (i = 0; i < 100000; i++) {
//Code
}
console.timeEnd();
Try it Yourself »
Definition and Usage
The console.timeEnd() method is the ending method of the timer.
This method is generally used to test the duration of program execution.
console.time()The console.time() method is the starting method of the timer.
If a page needs to use the timer in multiple places, you can add a label parameter to set it.
Tip:While testing this method, the console needs to be visible (press F12 in the browser to open the console).
Syntax
console.timeEnd(label)
Browser Support
The numbers in the table indicate the first browser version number that supports this method.
| Method | |||||
|---|---|---|---|---|---|
| console.timeEnd() | Yes | 11 | 10 | 4 | Yes |
Parameter Description
| Parameter | Type | Description |
|---|---|---|
| label | String | Optional. Used to set a label for the timer. |
| tablecolumns | Array | Optional. An array, the names of the table header columns. |
More Examples
Example
Using the label parameter:
console.time("Example");
for (i = 0; i < 100000; i++) {
//Code
}
console.timeEnd("Example);
Try it Yourself »
Example
Test which code executes faster
var i;
console.time("for loop test:");
for (i = 0; i < 100000; i++) {
//Code
}
console.timeEnd("for loop ended.");
i = 0;
console.time("while loop test:");
while (i < 1000000) {
i++
}
console.timeEnd("while loop test ended.");
Try it Yourself »
Console Object