Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
![](/static/devrant/img/pipeless-devrant-banner-white.png)
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
atheist92373yIf you're in a compiled language, that's a compiler bug (g++ will generate the same assembly for both), if you're in an interpreted language... Well, don't worry about speed...
-
C0D4682463yFor() might be faster.
But
foreach(){
foreach(){
foreach(){
}
}
}
Is soooooo much easier to read 🤪 -
Root823423yLooping and incrementing a register is faster than loading an object reference out of a struct array and incrementing a pointer by the struct size? Whoda thunk
-
Gimme numbers and tell me that any user will notice this.
I will find a lot of other numbers the user will notice a lot more. :)
Microoptimization - if unnecessary - is really just a shiny way to screw yourself over and over for nuts. -
Worrying about that kind of stuff in JS is kinda funny. Even in the fastest compiled language I wouldn‘t care unless it‘s a really huge amount of iterations.
-
@lopu yeah. It’s still only a constant/linear factor. Optimizing it is kinda pointless. Because on a different machine/browser it can still be too slow to be acceptable.
Optimizing whats going on in each iteration will be better, but still linear.
The real solution is bringing down the iteration count. I don’t know the context of what you are using the loop for, but on other platforms there are mechanisms like lazy lists in UI which are solutions for that problem.
Me when I found out for() is 5-6 times more efficient that .forEach
joke/meme
javascript