The console.time() method starts a timer you can use to track how long an operation takes. You give each timer a unique name, and may have up to 10,000 timers running on a given page. When you call console.timeEnd() with the same name, the browser will output the time, in milliseconds, that elapsed since the timer was started. MDN
Syntax :
we first define our timer with console.time and then write the code we need to measure how long it takes to execute and lastly we stop the timer and log the time with console.timeEnd()
you can use console.time()
to measure how long any task in your code will take to run, so it’s useful what tasks takes long time and then you split the logic of this task into smaller tasks to improve your code performance, since javascript is single-threaded language, any task that take a lot of time will effect your site or application performance badly or even make it not interactive for seconds which is the worst thing may happen.
Thanks for reading, and feel free to ask any question about javascript or about this series and i appreciate any feedback to improve My content.
find me on twitter, github and my portfolio.
Top comments (0)