1D vs 2D Array

Benchmark created on


Setup

var arrDim = 10000;
var actualArrDim = 10;

class Foo {}

var oneDimArr = new Array(arrDim).fill(new Foo());
var twoDimArr = new Array(actualArrDim).fill(new Array(Math.round(arrDim / actualArrDim)).fill(new Foo()));
console.log(twoDimArr)

Test runner

Ready to run.

Testing in
TestOps/sec
2D
for (let i = 0; i < twoDimArr.length; ++i) {
	for (let j = 0; j < twoDimArr[i].length; ++j) {
	
	}
}
ready
1D
for (let i = 0; i < oneDimArr.length; ++i) {
	
}
ready

Revisions

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