14:08
<canadahonk>
Also, for (var i = 0, l = array.length; i < l; i++) {, which remains the faster pattern on XS, fwiw.

for..of is fastest in my engine lol

16:15
<kriskowal>

for..of is fastest in my engine lol

I should check, that might be the case for XS. Just, there is no loop optimization around a constant guard in XS.
19:18
<Richard Gibson>

I just tested i < l vs. i < arr.length vs. for..of over a 500k array of numbers across implementations on amd64 (excluding Hermes for lack of async function support that my tool currently requires):

  • GraalJS and SpiderMonkey and V8 all favor the first two forms about equally, and it's much faster than for..of (8x for V8, 5x for the other two)
  • in JSC, i < l is about 2.5x the speed of both i < arr.length and for..of (but the former is about 10% faster than the latter)
  • in XS, i < l is almost 50% faster than i < arr.length, which is almost 50% faster than for..of
  • in QuickJS, for..of is about 12% faster than i < l and 35% faster than i < arr.length (the only tested implementation that favors for..of)
  • in absolute terms, V8 is about 2 times faster than JSC, which is about two times faster than SM, which is almost 3 times faster than GraalJS, which is almost 10 times faster than QuickJS, which is almost 2 times faster than XS