Array.push vs new Array(size)

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
new Array(size)
  const a = new Array(10000)
  for (let i = 0; i < 10000; i++) {
    a[i] = i * 2
  }
ready
Array.push
  const a = []
  for (let i = 0; i < 10000; i++) {
    a.push(i * 2)
  }
ready
Array.from
const a = Array.from({ length: 10000 }, (_, i) => i * 2)
ready

Revisions

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