Performance of Array vs. Object (v16)

Revision 16 of this benchmark created on


Description

After seeing http://jsperf.com/javascript-associative-vs-non-associative-arrays, I thought the test could be improved.

Setup

var arr = [],
        obj_arr = [],
        obj = {},
        obj_obj = {},
        i,
        times = 1000;
    
    for(i = 0; i < times; i+=1) {
        arr.push(i);
        obj[i] = i;
        obj_arr[i] = {v: 1};
        obj_obj[i] = {v: 1};
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Array Performance
for (var x=0; x<arr.length; x+=1) {
    arr[x]
}
ready
Object Performance
for (var x in obj) {
    obj[x]
}
ready
Object Performance using known keys
for (var x=0; x<times; x+=1) {
    obj[x]
}
ready
Array of objects Performance
for (var x=0; x<obj_arr.length; x+=1) {
    obj_arr[x]
}
ready
Object of objects Perfomance
for (var x=0; x<times; x+=1) {
    obj_obj[x]
}
ready

Revisions

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