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
Latest comments (20)
Pi
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. 🖖Thank you for sharing this!
You're most welcome
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
Tools like jsbench.me/ are also great when you need to compare different snippets.
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 😄
Nice to know there is such feature. Thanks!
if you console.log(console) you will see it has a lot of useful methods
Thank you for this information ,It's a really new for me
But how can I use it in C++ language?...
I am glad I could help
Useful post. Thank you for sharing!
I am really glad you found this helpful
Some comments may only be visible to logged-in visitors. Sign in to view all comments.