1D vs 2D Array (v2)

Revision 2 of this 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
/**
 * The larger the arrays are the close the
 * performance of a 2D array gets to the 1D as
 * the initial cost of counting the length of the
 * array at each index gets more and more 
 * insignificant.
 */
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.