The results don't surpreise me, because you card stacked the demo by using the slow push method, and which browser makers still haven't put much optimization into.

On paper map should be hte slower method, and the only reason it isn't is they've put massive amounts of effort into optimizing it whilst leaving for loops to rot.

Why should map be slower? And why would it actually use more memory and/or cause memory thrashing?

You're putting the overhead of a function inside the loop! Remember, optimizing inside a loop is not premature optimization, it's good practice. In that way the Array methods should be inefficient and are bad practice.

Though at least does something, unlike the mind-numbingly idiotic Array.foreach.

But seriosuly, you card stacked things in's favor.

You test that you'll find the two trade blows every time you run it under v8. Though you also card stacked it in terms of execution order. If you flip which test is done first, whichever one is second is faster.

For example:

Chrome, Map first:

Chrome, Array First

So your conclusions don’t line up with reality. In fact it reeks of you coming to a conclusion and then manufacturing loaded tests for the sole purpose of supporting your conclusion.



Accessibility and Efficiency Consultant, Web Developer, Musician, and just general pain in the arse

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store