Array fill

Benchmark created on


Setup

const size = 1000

Test runner

Ready to run.

Testing in
TestOps/sec
for loop
const mem = [];
for (let i = 0; i < size; i++) {
  const row = [];
  for (let j = 0; j < size; j++) {
    row.push(i * size + j);
  }
  mem.push(row);
}
ready
Array.from
Array.from({length: size}, (_, i) => Array.from({length: size}, (_, j) => i * size + j));
ready
spread
[...Array(size)].map((_, i) => [...Array(size)].map((_, j) => i * size + j));
ready

Revisions

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