Object hasOwnProperty vs Array indexOf (v10)

Revision 10 of this benchmark created 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 = {},
      array = [],
      i, test = 1001;
  
  for (i = 0; i < 1000; i++) {
   object['something' + i] = true;
   array.push('something' + i);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
object.hasOwnProperty
object.hasOwnProperty('something' + test)
ready
array.indexOf
array.indexOf('something' + test) !== -1
ready
in
('something' + test) in object
ready
direct
object['something' + test] === true
ready

Revisions

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