HTML DOM console.timeEnd() method
Example
The actual time required to execute 100,000 times:
console
.
time
(
)
;
for
(
i
=
0
;
i
<
100000
;
i
++
)
{
//
Code section
}
console
.
timeEnd
(
)
;
Try it »
Definition and Usage
The console.timeEnd() method serves as the ending method of the timer.
This method is generally used to test the execution time of a program.
console.time() method is the starting method of the timer.
If a page needs to use a timer in multiple places, you can add a label parameter to distinguish them.
Tip: During testing of 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 that supports this method.
| Method | |||||
|---|---|---|---|---|---|
| console.timeEnd() | Yes | 11 | 10 | 4 | Yes |
Parameter Description
| Parameters | Type | Description |
|---|---|---|
| label | String | Optional. Used to set a label for the timer. |
| tablecolumns | Array | Optional. An array containing the names of the table header columns. |
More examples
Example
Use the label parameter:
console
.
time
(
"
Runoob
"
)
;
for
(
i
=
0
;
i
<
100000
;
i
++
)
{
//
Code section
}
console
.
timeEnd
(
"
Runoob);
Try it »
Example
Test which code executes faster
var
i
;
console
.
time
(
"
for loop test:
"
)
;
for
(
i
=
0
;
i
<
100000
;
i
++
)
{
//
Code section
}
console
.
timeEnd
(
"
for loop ended.
"
)
;
i
=
0
;
console
.
time
(
"
while loop test:
"
)
;
while
(
i
<
1000000
)
{
i
++
}
console.
timeEnd
(
"
while loop test ended.
"
)
;
Try it »
Console object