array vs obj (v8)

Revision 8 of this benchmark created by Marco Pfeiffer on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var collectionObj = {};
  var collectionArr = [];
  
  for (var i = 0; i < 1000; i++) {
   collectionObj["string" + i] = "doesn't matter";
   collectionArr.push("string" + i);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
array (indexOf)
collectionArr.indexOf("string500")
 
ready
array (jQuery)
jQuery.inArray("string500", collectionArr)
ready
obj (hasOwnProperty)
collectionObj.hasOwnProperty("string500")
ready
obj (in)
("string500" in collectionObj)
ready
obj (undef)
(collectionObj["string500"] !== undefined)
ready
obj (typeof)
(typeof collectionObj["string500"] !== "undefined")
ready

Revisions

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