Object: hasOwnProperty vs. propertyIsEnumerable

Benchmark created on


Preparation HTML

<script>
  Object.prototype.asd = 'this is unwanted';
  var dummy, myObj = {
   1: 'foo',
   2: 'bar',
   3: 'baz',
   4: 'qux'
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
for (var o in myObj) {
 if (myObj.hasOwnProperty(o)) {
  var dummy = myObj[o];
 }
}
ready
propertyIsEnumerable
for (var o in myObj) {
 if (myObj.propertyIsEnumerable(o)) {
  var dummy = myObj[o];
 }
}
ready

Revisions

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