Array push method vs setting via key

Benchmark created on


Setup

const ARRAY_SIZE = 1000;

Test runner

Ready to run.

Testing in
TestOps/sec
Push
const arr = [];
for (let i = 0; i < ARRAY_SIZE; i++) {
	arr.push(i);
}
ready
Key (pre init array with size)
const arr = Array(ARRAY_SIZE);
for (let i = 0; i < ARRAY_SIZE; i++) {
	arr[i] = i;
}
ready
Key
const arr = [];
for (let i = 0; i < ARRAY_SIZE; i++) {
	arr[i] = i;
}
ready

Revisions

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