sparse arrays vs objects (v7)

Revision 7 of this benchmark created on


Setup

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,'James Bond2', 82, 402],
      ['Superman', 9999, 36,'Superman2', 99992, 362]
    ];
    window.items2=[];
    items2 = [{
      Name: 'James Bond', strength: 8,
      coolness: 40,
      Name2: 'James Bond2', strength2: 82,
      coolness2: 402
    }, {
      Name: 'Superman', strength: 9999,
      coolness: 36,
     Name2: 'Superman2', strength2: 99992,
      coolness2: 362
    }];
    var item1=items1[1];
    var item2=items2[1];

Test runner

Ready to run.

Testing in
TestOps/sec
array get a
var search1;
search1 = item1[4];
ready
object get b
var search2;
search2 = item2["strength2"];
ready
object get
var result;
for (var i = 0; i < 25; i++)
result = obj[i];
ready
array get
var result;
for (var i = 0; i < 25; i++)
result = arr[i];
ready

Revisions

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