Object keys iteration

JavaScript performance comparison

Revision 30 of this test case created by Pencroff

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

      
<script>
Benchmark.prototype.setup = function() {
  var data = {};
  var data_copy = {};
    
    for (var k = 0; k < 750; k+=1) {
    if (k<500) {
     data[k] =  'user ' + k;
   } else {
     data[k] = undefined;
   }
    
    }
  
  var keys = Object.keys(data);
  var len = keys.length;
  var i = 0;
  var prop;
  

};
</script>

Preparation code output

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
for-in
for (var key in data) {
  data_copy[key] = data[key];
}
pending…
object-keys
Object.keys(data).forEach(function(element, index, array) {
  data_copy[element] = data[element];
});
pending…
object-keys 2
while (i < len) {
  prop = keys[i];
  data_copy[prop] = data[prop];
  i+=1;
}
pending…
object-keys 3
for (i = 0; i < len; i+=1) {
  prop = keys[i];
  data_copy[prop] = data[prop];
}
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