|
|
|
|
|
by bhaney
429 days ago
|
|
I wish authors would actually test their performance claims before publishing them. I quickly benchmarked the two code snippets: arr.slice(10, 20).filter(el => el < 10).map(el => el + 5)
and arr.values().drop(10).take(10).filter(el => el < 10).map(el => el + 5).toArray()
but scaled up to much larger arrays. On V8, both allocated almost exactly the same amount of memory, but the latter snippet took 3-4x as long to run. |
|
JavaScript engines have put a lot of effort into optimising Array, so that these sorts of patterns can run significantly faster than they have any right to.
Iterators are comparatively new, and haven’t had so much effort put into them.