You ever wanted to know how long does a block of your code takes to execute? Well you have come to the right place.
You can simply wrap your block of code with console.time function to measure how long your code took to execute.
console.time("Label A")
let num = -999999
for(let i = 0; i < 99999; i++){
num++
}
console.log(num)
console.timeEnd("Label A")
Make sure to check out my other articles also
Top comments (20)
Yeah, really usefull!
You can also use
performance.now
in case you need more precision, though you need to do the calculation yourself.Yes we learn something new everyday 😄
The
console.log
statement on the line 6 would change the result a lot. I'd move that afterconsole.timeEnd,
just to make sureconsole.log
doesn't affect my analysis. 🖖Tools like jsbench.me/ are also great when you need to compare different snippets.
Useful post. Thank you for sharing!
I am really glad you found this helpful
Thank you for sharing this!
You're most welcome
Nice to know there is such feature. Thanks!
if you console.log(console) you will see it has a lot of useful methods
Sweet, thanks for sharing!
I am really glad you liked it
It's amazing. Thanks for sharing. Now I can know how fast I am, I mean my code.
looks really cool
Your content is so useful!
I just give you a follow.
Keep g bro!❤
I'm really grateful for that
Thank you
Some comments may only be visible to logged-in visitors. Sign in to view all comments.