JS: For loop vs Array.indexOf (v305)

Revision 305 of this benchmark created by Test on


Description

Testing speed of a standard for loop vs. Array.indexOf.

Setup

var b={a:1},arr=[{},{},{},{},{},{},{},{},b,{},{},{},{},{},{},{},{}];
    
    function cleanestIndexOf(arr,thing){
      for(var l=arr.length;arr[--l]!==thing;);
      return l;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Cleanest Index Of
cleanestIndexOf(arr,b);
ready
indexOf
arr.indexOf(b);
ready

Revisions

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