Object hasOwnProperty vs Array indexOf (v12)

Revision 12 of this benchmark created by Steven Vachon on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/ext-core/3/ext-core.js"></script>
<script src="//www.cinsoft.net/mylib099-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/mootools/1.3/mootools-yui-compressed.js"></script>
<script>
  var object = {};
  var array = [];
  var len = 1000;
  var str = "something";
  var needle = str + (len+1);
  
  for (var i=0; i<1000; i++) {
    object[str + i] = true;
    array.push(str + i);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
object.hasOwnProperty
object.hasOwnProperty(needle) === true
ready
array.indexOf
array.indexOf(needle) !== -1
ready
in
needle in object === true
ready
direct #1
object[needle] === true
ready
direct #2
object.something1001 === true
ready

Revisions

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