Performance of Array vs. Object (v130)

Revision 130 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 = { array:[] };
    
    for(i = 0; i < 10; i++) {
        arr.push(i);
        obj.array.push(i);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Array Performance
for(var i = 0; i < arr.length; i++){
arr[i] = i;
};
ready
Object Performance
for(var i = 0; i < arr.length; ++i){
arr[i] = i;
};
ready
Object Performance using known length
var x = arr.length;
while(--x){
arr[x] = x;
};
ready
Using Object.keys()
var x = obj.array.length;
while(--x){
obj.array[x] = x;
};
ready
Array Performance known length
var x = 0;
while(++x < obj.array.length){
obj.array[x] = x;
};
ready
Array using .foreach
for(var i = 0; i < obj.array.length; i++){
obj.array[i] = i;
};
ready

Revisions

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