Array.from vs Array.fill+map

Benchmark created by edwjusti on


Setup

const mapFn = () => ({});

Test runner

Ready to run.

Testing in
TestOps/sec
Array.from
const arr = Array.from({
  length: 100
}, mapFn);
ready
Array.fill
const arr = Array(100).fill().map(mapFn);
ready
for loop
const arr = [];
for (let index = 0; index++ < 100;) {
  arr.push(mapFn());
}
ready

Revisions

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

  • Revision 1: published by edwjusti on