Performance of Array vs. Object (v93)

Revision 93 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 = [],
        i,
        obj = {};
    for(i = 0; i < 10000; i += 1) {
        var o = {payload:i};
        arr.push(o);
        obj[i] = o;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Array Performance
var sum = 0;
for (var x=arr.length - 1; x--;     ) {
    sum += arr[x].payload
}
ready
Object Performance
var sum = 0;
for (var x=0; x<10000; ++x) {
    sum += arr[x].payload
}
ready
Object Performance using known length
var sum = 0;
for (var x=arr.length; --x;     ) {
    sum += arr[x].payload
}
ready
Using Object.keys()
 
ready
Array Performance known length
 
ready

Revisions

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