-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace forEach() with native for-loops for performance improvement #287
Comments
Hi @coffeeandwork , there are something wrong here, I published a js perf here (https://jsperf.app/tecele) and got some results. I always understood that the native for loop is the fastest but, why these results? For me it's ok to change to native for loop too (but this is strange). Chrome 123 (3 runs)Firefox 124 (3 runs) |
I believe that modern browsers can do some performance trick here. 🪄 |
I think it's more likely that the |
#287 replace forEach() with native for-loops
Nice! |
In this benchmark I have tested various looping constructs: https://jsbench.me/dulu7atajk/4.
forEach()
appears slower by an order of magnitude compared to a native for-loop. This makes sense because for each iteration insideforEach()
we are doing a callback invocation that comes with its extra costs that we don't incur with a native for loop.The text was updated successfully, but these errors were encountered: