Object detection (v11)

Revision 11 of this benchmark created on


Description

http://stackoverflow.com/questions/7174748/javascript-object-detection-dot-syntax-versus-in-keyword/7174775#7174775

Preparation HTML

<script>
  var object = {property: 0};
  
  function has(obj, prop) {
      return Object.prototype.hasOwnProperty.call(obj, prop);
  }

  function key_present(obj, prop) {
      return Object.keys( obj ).indexOf( prop ) === -1 ? false : true;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
if(object.property)
if(object.property) {

}
ready
if('property' in object)
if('property' in object) {

}
ready
if(object.hasOwnProperty('property'))
if(object.hasOwnProperty('property')) {

}
ready
if(has(object, 'property'))
if(has(object, 'property')) {

}
ready
if(key_present(object, 'property'))
if(key_present(object, 'property')) {

}
ready
if(object[ 'property' ])
if(object[ 'property' ]) {
}
ready

Revisions

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