4 ms·
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
by dahart 10y ago
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)