sparse arrays vs objects (v3)

Revision 3 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();

Test runner

Ready to run.

Testing in
TestOps/sec
not relevant
obj = {}
for (var i = 0; i < 1; i++)
obj[~~ (Math.random() * 1000)] = Math.random();
ready
not relevant
arr = [];
for (var i = 0; i < 1; i++)
arr[~~ (Math.random() * 1000)] = Math.random();
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.