Object detection

JavaScript performance comparison

Test case created

Info

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

Preparation code

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

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
if(object.property)
if(object.property) {

}
pending…
if('property' in object)
if('property' in object) {

}
pending…
if(object.hasOwnProperty('property'))
if(object.hasOwnProperty('property')) {

}
pending…
if(has(object, 'property'))
if(has(object, 'property')) {

}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment