HTML DOM console.time() method
- Halaman sebelumnya table()
- Halaman berikutnya timeEnd()
- Kembali ke lapisan atas Objek Window Console
Definition and Usage
console.time() method starts the timer in the console view.
This method allows you to time certain operations in code for testing purposes.
Please use console.timeEnd() method End the timer and display the result in console.view.
Use the label parameter to name the timer, and then you can set multiple timers on the same page.
Tip:When testing console methods, make sure the console view is visible (press F12 to view the console).
Instance
Example 1
How long does it take to execute a for loop 100,000 times?
console.time(); for (i = 0; i < 100000; i++) { // some code } console.timeEnd();
Example 2
Using label parameter:
console.time("test1"); for (i = 0; i < 100000; i++) { // some code } console.timeEnd("test1");
Example 3
Which is faster, for loop or while loop?
var i; console.time("test for loop"); for (i = 0; i < 1000000; i++) { // some code } console.timeEnd("test for loop"); i = 0; console.time("test while loop"); while (i < 1000000) { i++ } console.timeEnd("test while loop");
Syntax
console.time(label)
Parameter Value
Parameter | Type | Description |
---|---|---|
label | String | Optional. Use the label parameter to name the timer. |
Browser Support
Nombor di dalam tabel menunjukkan versi paling awal penggunaan penuh untuk metod ini.
Metode | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
console.time() | Dukungan | 11 | 10 | 4 | Dukungan |
- Halaman sebelumnya table()
- Halaman berikutnya timeEnd()
- Kembali ke lapisan atas Objek Window Console