I ran across a jsperf.com test of a for loop vs foreach and I was surprised at the difference when running the test in Chrome 38:
The for loop consistently came out over 40 times faster than the foreach.
I ran across a jsperf.com test of a for loop vs foreach and I was surprised at the difference when running the test in Chrome 38:
The for loop consistently came out over 40 times faster than the foreach.
4 replies on “JavaScript Performance: for vs. foreach”
I believe JavaScript compiler eliminates the for loop at all in this case. I modified the test for more realistic results: http://jsperf.com/foreach-vs-loop/77
Since jsPerf is down, what was the result?
That is what the screenshot was for 🙂
I believe he’s talking about ivan’s test though.