arraytest

JavaScript performance comparison

Revision 2 of this test case created by APXEOLOG

Preparation code

<script>
  Benchmark.prototype.setup = function() {
var Z = [];
Z[0] = { data : 1 };
Z[1] = { data : 1 };
Z[2] = { data : 1 };
Z[3] = { data : 1 };
Z[4] = { data : 1 };

    var A = []; var AKeys = [0, 1, 2, 3, 4];
for (var i = 0; i < AKeys.length; i++) A[AKeys[i]] = { data : 1 };

    var B = []; var BKeys = [0, 1, 10, 100, 1000];
for (var i = 0; i < BKeys.length; i++) B[BKeys[i]] = { data : 1 };

    var C = {}; var CKeys = ['index0', 'index1', 'index2', 'index2', 'index4'];
for (var i = 0; i < CKeys.length; i++) C[CKeys[i]] = { data : 1 };
  };
</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
Flat array
for (var i = 0; i < AKeys.length; i++) A[AKeys[i]].data = i;
pending…
Flat not aligned array
for (var i = 0; i < BKeys.length; i++) B[BKeys[i]].data = i;
pending…
Assoc array
for (var i = 0; i < CKeys.length; i++) C[CKeys[i]].data = i;
pending…
Simple
for (var i = 0; i < 4; i++) Z[i].data = i;
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