Measure the time taken by a function to execute - console.time & console.timeEnd ⏳⏲
Pranjal Jately
Posted on September 6, 2020
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...
Pranjal Jately 👨🏽💻@pjately💡 #JavaScript tip: console.time & console.timeEnd ⏲
I'm no performance expert, but TIL a quick and easy way to measure the time it takes code to run ⬇
#100DaysOfCode #webdev #CodeNewbie #LearnInPublic #React16:37 PM - 03 Jul 2020
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.
💖 💪 🙅 🚩
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
javascript Measure the time taken by a function to execute - console.time & console.timeEnd ⏳⏲
September 6, 2020