array vs obj (v11)

Revision 11 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 = [];
  var inA = function(s,a){
     if (typeof a[s] == "undefined"){
        return false;}
     else{
       return true;}
};
  
  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
with object
collectionObj.hasOwnProperty("string500");
ready
with array
jQuery.inArray("string500", collectionArr)
ready
with JS array
inA("string500", collectionArr)
ready

Revisions

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