Array Performance (v2)

Revision 2 of this benchmark created on


Description

This is a test to show different array instantiation and fill methods. Pre allocation runs circles around dynamic allocation

Setup

const TOTAL = 10000000

Test runner

Ready to run.

Testing in
TestOps/sec
for loop
let arr = []

for (let i = 0; i <= TOTAL; i++){
	arr.push(i)
}
ready
new Array
let arr = new Array(TOTAL)

for (let i = 0; i <= TOTAL; i++){
	arr[i] = i
}
ready
new array fill
let arr = new Array(TOTAL).fill(0)

for (let i = 0; i <= TOTAL; i++){
	arr[i] = i
}
ready
random
let arr = []
arr.lenth = TOTAL;

for (let i = 0; i <= TOTAL; i++){
	arr[i] = i
}
ready

Revisions

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