3 ms·
Actually, the forEach version can end up faster than the let version... especially if you self-host forEach so that the JIT can do its job (e.g. inlining the LI
by bzbarsky 15y ago
Actually, the forEach version can end up faster than the let version... especially if you self-host forEach so that the JIT can do its job (e.g. inlining the LIB_addEventListener calls so there aren't actually any function invocations, etc).
- masklinn 15y ago> Actually, the forEach version can end up faster than the let version... Theoretically maybe, but I've yet to see that. A regular `for(;;)` is generally 3-5 times faster than using `Array.prototype.forEach`. Re. JIT, hand-rolling a foreach in javascript can be up to twice as fast as the native one, depending on the features you leave out.
- bzbarsky 15y ago> Theoretically maybe, but I've yet to see that Compare the let version to the code in https://bugzilla.mozilla.org/show_bug.cgi?id=602132 https://bugzilla.mozilla.org/show_bug.cgi?id=602132