1D VS 2D

JavaScript performance comparison

Revision 4 of this test case created by Sadiquo

Info

1D VS 2D

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var array1 = [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27],
        array2 = [
        [1, 2, 3, 4, 5, 6, 7, 8, 9],
        [10, 11, 12, 13, 14, 15, 16, 17, 18],
        [19, 20, 21, 22, 23, 24, 25, 26, 27]
        ],
        i, e;
};
</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
1D
for (i = 0; i < 27; i++) {
  array1[i];
}
pending…
2D-boucle
for (i = 0; i < 9; i++) {
  for (e = 0; e < 3; e++) {
    array2[e][i];
  }
}
pending…
2D-increment
e = -1;
for (i = 0; i < 27; i++) {
  if (i % 9 == 0) e++;
  array2[e][i];
}
pending…
2D-parse
for (i = 0; i < 27; i++) {
  array2[parseInt(i / 9)][i % 9];
}
pending…
2D-floor
for (i = 0; i < 27; i++) {
  array2[Math.floor(i / 9)][i % 9];
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment