Measure the time taken by a function to execute - console.time & console.timeEnd ⏳⏲

pranjaljately

Pranjal Jately

Posted on September 6, 2020

Measure the time taken by a function to execute - console.time & console.timeEnd ⏳⏲

A quick and easy way to measure the time it takes code to run is by using console.time in conjunction with console.timeEnd.

All you need to do is surround the code or function call you desire to evaluate with console.time and console.timeEnd respectively...

console.time(<label>) starts a timer with a given (unique) label and console.timeEnd(<label>) stops the timer with the corresponding label (the labels must match for this to work).

Once stopped, the elapsed time is automatically displayed in the console 🤯

Drop a comment if you've ever used this technique to measure the performance of your code.
Have a good one.

💖 💪 🙅 🚩
pranjaljately
Pranjal Jately

Posted on September 6, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related