fill then map vs array.from vs generator (v6)

Revision 6 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Fill then map
const ret = new Array(100).fill('').map((_, i) => i + i)
ready
array.from then map
const ret = Array.from({length: 100}).map((_, i) => i + i)
ready
array.from with second arg
const ret = Array.from({length: 100}, (_, i) => i + i)
ready
array.from with generator
function* range(count) {
  for (let i = 0; i < count; ++i) { yield i + i }
}

const ret = Array.from(range(100))
ready
baseline
const ret = new Array(100)
for (let i = 0; i < 100; ++i) {
  ret[i] = i + i
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.