Object hasOwnProperty vs Array indexOf (v2)

Revision 2 of this benchmark created by Jacky Nguyen on


Preparation HTML

<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.