indexOf vs. object (just text)

Benchmark created on


Preparation HTML

<script>
  var arr = ["asdf", "sdfg", "dfgh", "fghj", "ghjk", "hjkl", "jklo"];
  var obj = {};
  
  arr.forEach(function(i) {
    obj[i] = true;
  });
  
  var searched = "dfgh";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Object
return obj[searched];
ready
Array
return arr.indexOf(searched) !== -1;
ready

Revisions

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