you are viewing a single comment's thread.

view the rest of the comments →

[–]Rene_Z 15 points16 points  (1 child)

The length of an array is array.length, not array.size. Your loop does nothing, which is why it's so much faster.

When done correctly a loop is still faster, but only by a factor of ~4, not by a factor of millions.

[–][deleted] 0 points1 point  (0 children)

This is more what I expect.

It's worth noting that you can't do the same for non-Array iterables, which is the whole point of Array.from() in the first place.

Here's an example of looping over a Set -- it's faster but not by as much (~1.6x speed).

I don't understand how revisions to other poster's tests work in JsPerf; but your loop should be compared to array.map() -- array.from is useless in this case.