I guess the Mozilla developers heard you.
Johannes Rebhan
83

I think the test cases are set up incorrectly. I ran the test on Chrome Canary Mac and the result were showing that the for loop was 66% slower than the forEach, which doesn’t make any sense.

The issue is that the function add have no impact on the state of the application, so it’s up to the JS engine to optimize it away entirely. After modifying the test cases to prevent this ( https://jsperf.com/foreach-vs-for-with-callbacks-not-void ) the results are more in line with what you’d expect on Chrome : forEach is ~70% slower :(

On Firefox, for was 30% slower in the original test. In the modified test, forEach is just a little slower than for (which is impressive and doesn’t really change the point of your comments).

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.