10
lopu
3y

Me when I found out for() is 5-6 times more efficient that .forEach

Comments
  • 15
    If 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...
  • 0
    For() might be faster.

    But

    foreach(){
    foreach(){
    foreach(){
    }
    }
    }

    Is soooooo much easier to read 🤪
  • 5
    Looping 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
  • 0
    too bad if you use elixir tho
  • 2
    Laughs in C
  • 1
    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.
  • 0
    @IntrusionCM with animation work it's definitely noticeable
  • 1
    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.
  • 0
    @Lensflare like I said with animation it really is noticeable
  • 0
    @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.
Add Comment