Re:How much your computer can do in a second
by dahart on Monday March 27, 2017 @01:56PM
(#13970079)
I don't really know why, and I have heard there are large discrepancies from browser to browser. It is a function call per iteration, or even a closure, so I'm guessing it may often be difficult to recognize and optimize out the function call, or maybe some browsers haven't gotten around to it yet, I don't know.
This also depends on what you're comparing. Map always allocates a new array. In my Chrome 57 right now, map() is 4x slower than new array + a for loop of push().
But it's 100x faster to re-use an existing array... (a for loop of array element assignment)
Wow, really? Any idea why? Seems odd when map() imposes fewer guarantees and can be implemented, in the worst case, with a for() loop...