for in vs Object.getOwnPropertyNames

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var isE1 = function(obj) {
      for (var key in obj) return false; return true;
  }
  var isE2 = function(obj) {
      return Object.getOwnPropertyNames(obj).length === 0;
  }
  
  var o1 = {}, 
      o2 = {a: 1, b: 2, c: 3, d: 4, e: 5},
      o3 = {a: 1, b: 2, c: 3, d: 4, e: 5, tools:[
          {
              type:'refresh', tooltip: 'Refresh form Data', hidden:true,
              handler: function(event, toolEl, panel){ }
          },
          {
              type:'help', tooltip: 'Get Help',
              handler: function(event, toolEl, panel){ }
          }
      ], 
      type:'help',
      tooltip: 'Get Help',
      handler: function(event, toolEl, panel){ },
  };

};
</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
for in empty
var a = isE1(o1);
pending…
Object.... empty
var a = isE2(o1);
pending…
for in small
var a = isE1(o2);
pending…
Object.... small
var a = isE2(o2);
pending…
for in std
var a = isE1(o3);
pending…
Object.... std
var a = isE2(o3);
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