2 ms·
Function calls in JavaScript runtimes (including V8) are quite slow. Array.map/filter/forEach will always be slower than a for loop doing the same thing. I wri
by city41 13y ago
Function calls in JavaScript runtimes (including V8) are quite slow. Array.map/filter/forEach will always be slower than a for loop doing the same thing.
I write a lot of games and game related things in JavaScript, and this is actually a major reason why I now use CoffeeScript. Nice clean comprehension syntax and better performance.
- jwmerrill 13y agoArray.map/filter/forEach aren't just slow because of function call overhead. They have different semantics than the for loop that you'd typically write (and that Coffeescript generates), because they support things like arrays with non-incremental keys. See the reference implementation at [1]. [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map#compatibility https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- deleted 13y ago[deleted]