I have an array of arrays for drawing a tilemap on the screen (basically an array of columns, each column is an array of tiles). I have tried to speed up the drawing process by not setting the array indexes that contain empty tiles, but it is not any faster.
var a1 = [];
a1[0] = 1;
a1[100] = 1;
a1[200] = 1;
a1[300] = 1;
var a2 = [];
for( var i = 0; i <= 300; i++ ) {
a2[i] = 1;
}
When I compared the time taken to loop through these two 100,000 times, a2 was slightly faster. When I tried using ( for var x in y ) instead, both with an array and an object, they were 4 - 12 times slower.
If looping through an object is a lot slower, and removing 99% of the array (not just from the end) is not making it any faster, is there any way one could actually make it faster?