Performance of Array vs. Object

JavaScript performance comparison

Revision 19 of this test case created by Jamie Olson


After seeing, I thought the test could be improved.

variant of the original test - read only

Preparation code

Benchmark.prototype.setup = function() {
    var data = {},arr = [], obj = {},
    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

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

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

/*arr[idx] = a;

Object Performance
var idx = getRandomIndex(data),
a = data[idx]

/*obj[idx] = a;

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

1 comment

Jamie Olson (revision owner) commented :

Apparently, insertion into arrays and objects have pretty comparable performance.

Comment form temporarily disabled.

Add a comment