bidirectionalIndexOf

JavaScript performance comparison

Test case created by cc

Preparation code

<script>
var array=[],l=100000;
while(l--)array[l]=l;

function bidirectionalIndexOf(a,b,c,d,e){
 for(c=a.length,d=c*1;c--;){
  if(a[c]==b)return c;
  if(a[e=d-1-c]==b)return e;
 }
 return -1
}

function contains(a, obj) {
    var i = a.length;
    while (i--) {
       if (a[i] === obj) {
           return i;
       }
    }
    return -1;
}
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
bidirectionalIndexOf
var x=bidirectionalIndexOf(array,99999);
var y=bidirectionalIndexOf(array,55555);
var z=bidirectionalIndexOf(array,1);
pending…
indexOf
var x=array.indexOf(99999);
var y=array.indexOf(55555);
var z=array.indexOf(1);
pending…
lastIndexOf
var x=array.lastIndexOf(99999);
var y=array.lastIndexOf(55555);
var z=array.lastIndexOf(1);
pending…
contains
var x=contains(array,99999);
var y=contains(array,55555);
var z=contains(array,1);
pending…

Compare results of other browsers

Revisions

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

0 Comments