IndexOf vs object lookup (existant keys) (v32)

Revision 32 of this benchmark created by sharon on


Preparation HTML

<script>
  var alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
  
  var arr = [];
  var obj = {};
  
  alphabet.forEach(function(char){
    for (var i = 1; i<10; i++){
      arr.push(char);
      obj[char] = 1;
      char += char;
    }
  });
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
if (arr.indexOf('a') !== -1) {}
ready
Object property access
if (obj.a) {}
ready
Object in
if ('a' in obj) {}
ready
Object.hasOwnProperty
if (obj.hasOwnProperty('a')) {}
ready
Object ['lookup']
if (obj['a']) {}
ready

Revisions

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