DEV Community

Cover image for How fast is your code?

How fast is your code?

Shuvo on October 18, 2021

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 ...
Collapse
 
nombrekeff profile image
Keff

Yeah, really usefull!

You can also use performance.now in case you need more precision, though you need to do the calculation yourself.

Collapse
 
0shuvo0 profile image
Shuvo

Yes we learn something new everyday 😄

Collapse
 
yatki profile image
Mehmet Yatkı • Edited

The console.log statement on the line 6 would change the result a lot. I'd move that after console.timeEnd, just to make sure console.log doesn't affect my analysis. 🖖

Collapse
 
lgrammel profile image
Lars Grammel

Tools like jsbench.me/ are also great when you need to compare different snippets.

Collapse
 
rahulp772 profile image
Rahul Prajapati

Useful post. Thank you for sharing!

Collapse
 
0shuvo0 profile image
Shuvo

I am really glad you found this helpful

Collapse
 
_pankajc profile image
Pankaj

Thank you for sharing this!

Collapse
 
0shuvo0 profile image
Shuvo

You're most welcome

Collapse
 
blackr1234 profile image
blackr1234

Nice to know there is such feature. Thanks!

Collapse
 
0shuvo0 profile image
Shuvo

if you console.log(console) you will see it has a lot of useful methods

Collapse
 
lgrammel profile image
Lars Grammel

Sweet, thanks for sharing!

Thread Thread
 
0shuvo0 profile image
Shuvo

I am really glad you liked it

Collapse
 
manoj_shukla_10 profile image
Manoj Shukla • Edited

It's amazing. Thanks for sharing. Now I can know how fast I am, I mean my code.

Collapse
 
0shuvo0 profile image
Shuvo

looks really cool

Collapse
 
amk profile image
Amran AL Ketara

Your content is so useful!
I just give you a follow.
Keep g bro!❤

Collapse
 
0shuvo0 profile image
Shuvo

I'm really grateful for that
Thank you

Collapse
 
muhammadzaki693 profile image
muhammadzaki693

Pi

Collapse
 
ziaad25 profile image
ziaad25 • Edited

Thank you for this information ,It's a really new for me
But how can I use it in C++ language?...

Collapse
 
0shuvo0 profile image
Shuvo

I am glad I could help