Performance of Array vs. Object (v19)

Revision 19 of this benchmark created by Jamie Olson on


Description

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

variant of the original test - read only

Setup

var data = {},arr = [], obj = {},
        i;
    for(i = 0; i < 100000; i += 1) {
        data[i] = {payload:i};
    }
    
    function getRandomIndex(obj) {
       var idx = Math.floor(Math.random()*99999);
       if(false === data.hasOwnProperty(idx)) {
          while (false === data.hasOwnProperty(idx)) {
              idx = Math.floor(Math.random()*9999);
          }
       }
       return idx;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Array Performance
var idx = getRandomIndex(data),
a = data[idx]

/*arr[idx] = a;
*/
 
ready
Object Performance
var idx = getRandomIndex(data),
a = data[idx]

/*obj[idx] = a;
*/
ready

Revisions

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