sparse arrays vs objects (v9)

Revision 9 of this benchmark created on


Setup

window.obj = {};
    for (var i=0; i<500; i++)
        obj[~~(Math.random()*1000)] = Math.random();
    window.arr = [];
    for (var i=0; i<500; i++)
        arr[~~(Math.random()*1000)] = Math.random();

Test runner

Ready to run.

Testing in
TestOps/sec
object set
obj = {}
for (var i=0; i<500; i++)
    obj[~~(Math.random()*1000)] = Math.random();
ready
array set
arr = [];
for (var i=0; i<500; i++)
    arr[~~(Math.random()*1000)] = Math.random();
ready
object get
var result;
for (var i=0; i<500; i++) {
    result = obj[~~(Math.random()*1000)];
}
ready
array get
var result;
for (var i=0; i<500; i++) {
    result = arr[~~(Math.random()*1000)];
}
ready

Revisions

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