Performance of Array vs. Object (v78)

Revision 78 of this benchmark created by bluefireuoop on


Description

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

Setup

var i,
        obj = {}, arr1 = new Uint32Array(100000), arr2 = [], arr3 = [];
    
    for(i = 0; i < 100000; i += 1) {
        var p1 = i, p2 = i*i, p3 = Math.sin(i);
    
        obj[i] = {p1:p1, p2:p2, p3:p3};
        arr1[i] = p1;
        arr2[i] = p2;
        arr3[i] = p3;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Array Performance
var sum = 0;
for (var x=0; x<100000; ++x) {
    sum += arr1[x] + arr2[x] + arr3[x];
}
ready
Obj perf
var sum = 0;
for (var x=0; x<100000; ++x) {
    var o = obj[x];
    sum += o.p1 + o.p2 + o.p3;
}
ready

Revisions

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