sparse arrays vs objects (v5)

Revision 5 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],
      ['Superman', 9999, 36]
    ];
    window.items2=[];
    items2 = [{
      Name: 'James Bond', strength: 8,
      coolness: 40
    }, {
      Name: 'Superman', strength: 9999,
      coolness: 36
    }];

Test runner

Ready to run.

Testing in
TestOps/sec
array get a
var search1;
search1 = items1[1][2];
ready
object get b
var search2;
search2 = items2[1]["coolness"];
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.