Performance foreach Object

JavaScript performance comparison

Revision 71 of this test case created by foreach object

Preparation code

<script src='https://code.jquery.com/jquery-1.11.0.min.js'></script>
      
<script>
Benchmark.prototype.setup = function() {
  var i,
    obj = {};
  for (i = 0; i < 100000; i += 1) {
    var o = {
      payload: i
    };
    obj[i] = o;
  }
  
  var sum = 0;
  var keys = Object.keys(obj);
  var len = keys.length;
  var i = 0;

};
</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
jQuery Each
$.each(obj, function(k, v) {
    sum += v.payload;
});
pending…
Object Performance
for (var x in obj) {
  sum += obj[x].payload;
}
pending…
Using Object.keys()
for (var x = 0; x < keys.length; ++x) {
  sum += obj[keys[x]].payload
}
pending…
Object Keys - While
i = 0;
while (i < len) {
  sum += obj[keys[i]].payload
  i++;
}
pending…
Using Object.keys() II
for (var x = 0, k = Object.keys(obj); x < k.length; ++x) {
  sum += obj[k[x]].payload;
}
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