DEV Community

Pranjal Jately
Pranjal Jately

Posted on

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.

Top comments (0)