Object membership check speed (using branch results) (v7)

Revision 7 of this benchmark created by jimrandomh on


Preparation HTML

<script>
  var obj = {
   'apples': 1,
   'bananas': 1
  };
</script>

Setup

var x = 0;

Teardown


    console.log(x);
  

Test runner

Ready to run.

Testing in
TestOps/sec
in keyword
if ('apples' in obj) { x++; };
if ('not_here' in obj) { x++; };
if ('bananas' in obj) { x++; };
ready
dot syntax
if (obj.apples) { x++; };
if (obj.not_here) { x++;};
if (obj.bananas) { x++; };
ready
array syntax
if (obj['apples']) { x++; };
if (obj['not_here']) { x++; };
if (obj['bananas']) { x++; };
ready
hasOwnProperty
if (obj.hasOwnProperty('apples')) { x++; };
if (obj.hasOwnProperty('not_here')) { x++; };
if (obj.hasOwnProperty('bananas')) { x++; };
ready
Non-null
if (obj['apples'] != null) { x++; };
if (obj['not_here'] != null) { x++; };
if (obj['bananas'] != null) { x++; };
ready

Revisions

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