array vs obj (v13)

Revision 13 of this benchmark created 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
obj
collectionObj.hasOwnProperty("string500");
ready
array
jQuery.inArray("string500", collectionArr)
ready
array indexof
collectionArr.indexOf("string500") !== -1;
ready
not in object
collectionObj.hasOwnProperty("string1001");
ready
not in array
jQuery.inArray("string1001", collectionArr)
ready
not in array indexof
collectionArr.indexOf("string1001") !== -1;
ready

Revisions

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