sparse arrays vs objects

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    window.obj = {};
    for (var i = 0; i < 25; i++)
    obj[i] = Math.random();
    window.arr = [];
    for (var i = 0; i < 25; i++)
    arr[i] = Math.random();
    window.items1=[];
    items1 = [
      ['James Bond', 8, 40],
      ['Superman', 9999, 36]
    ];
    window.items2=[];
    items2 = [{
      Name: 'James Bond', strength: 8,
      coolness: 40
    }, {
      Name: 'Superman', strength: 9999,
      coolness: 36
    }];
};
</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
not relevant
var search1;
search1 = items1[1][2];
pending…
not relevant
var search2;
search2 = items2[1]["coolness"];
pending…
object get
var result;
for (var i = 0; i < 25; i++)
result = obj[i];
pending…
array get
var result;
for (var i = 0; i < 25; i++)
result = arr[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