3 ms·
I've expected the JS interpreter to optimize that out. Turns out I was wrong and the version from the article is even 40% slower for a loop that iterates over 5
by robryk 13y ago
I've expected the JS interpreter to optimize that out. Turns out I was wrong and the version from the article is even 40% slower for a loop that iterates over 5000 elements and does a trivial amount of work:
http://jsperf.com/for-loop-vs-for-in-loop/18 http://jsperf.com/for-loop-vs-for-in-loop/18
- inglor 13y agoYou're not giving the JIT a chance to warm up at all. Also, you're degrading into 'slow mode' because your array has different types. Basically, it looks like you're doing a lot of bad things to the JIT on purpose :P Both the different types and the delete (array with holes) are _very_ harmful for performance in v8.
- goldenkey 13y agoThe arrays with holes are called Sparse Arrays, I googled for 'sparse array v8 performance' and didn't find much, but I've previously seen a Google Presentation on a slide-sharing site that did mention how poor sparse arrays perform when compared to normal contiguous arrays.