JavaScript console.time() Method

You are Here:

JavaScript console.time() Method

The console.time() method starts a timer in the console view.

Using this method, you can track how long an operation takes.

Note: It is recommended to give unique name to each timer.

Speed Test for loop

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Check your console (Press F12).</p> <script> var i; console.time(); for(i = 0; i < 1000000; i++){ //dummy for loop } console.timeEnd(); </script> </body> </html>

Syntax

console.time(label)

Parameter Values

ValueTypeExplanation
labelOptionalThe name to give the new timer.

Speed Test while loop

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Check your console (Press F12).</p> <script> var i = 0; console.time("While loop"); while(i < 1000000){ //dummy While loop i++; } console.timeEnd("While loop"); </script> </body> </html>

Speed Test For loop vs While loop

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Check your console (Press F12).</p> <script> var i; console.time("For loop"); for(i = 0; i < 1000000; i++){ //dummy for loop } console.timeEnd("For loop"); i = 0; console.time("While loop"); while(i < 1000000){ //dummy while loop i++; } console.timeEnd("While loop"); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author