Multidimensional Versus Single Array Grid

JavaScript performance comparison

Test case created by Vaughn

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var tile = [];
    var tile2 = [];
    var test;
    var test2;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Multidimensional
for (var x = 0; x < 512; x++) {
  for (var y = 0; y < 512; y++) {
    tile[x] = tile[x] || [];
    tile[x][y] = "test";
  }
}

for (var x = 0; x < 512; x++) {
  for (var y = 0; y < 512; y++) {
    test = tile[x][y];
  }
}
pending…
Single Array
for (var x = 0; x < 512; x++) {
  for (var y = 0; y < 512; y++) {
    tile2[x + (512 * y)] = "test";
  }
}

for (var x = 0; x < 512; x++) {
  for (var y = 0; y < 512; y++) {
    test2 = tile2[x + (512 * y)];
  }
}
pending…

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

Compare results of other browsers

0 comments

Add a comment