Performance of Array vs. Object

JavaScript performance comparison

Revision 145 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [],
    i,
    obj = {};
  for (i = 0; i < 100000; i += 1) {
    var o = {
      payload: i
    };
    arr.push(o);
    obj[i] = o;
  }
  var arrLen = arr.length;
  var objLen = Object.keys(obj).length;

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Array Performance
var sum = 0;
pending…
Object Performance
var len = 0,
i = 0;
while (true) {
 if (obj[i]) len+=1;
 i++
}
pending…
Array performance (test fetching length)
var len = 0;
for (var i in obj) {
len += 1;
}
pending…
Object performance (test fetching length)
var len = Object.keys(obj).length;
pending…

Compare results of other browsers

Revisions

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

0 Comments