bidirectionalIndexOf

JavaScript performance comparison

Revision 10 of this test case created by

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 result = [];
var arrIndex = 0;
for(var i = 0; i<l;i++){
if(bidirectionalIndexOf(array,1) < 0){
    result[arrIndex] = i;
    arrIndex++;
}
}
pending…
indexOf
var result = [];
var arrIndex = 0;
for(var i = 0; i<l;i++){
if(array.indexOf(1) < 0){
    result[arrIndex] = i;
    arrIndex++;
}
}
pending…
lastIndexOf
var result = [];
var arrIndex = 0;
for(var i = 0; i<l;i++){
if(array.lastIndexOf(1) < 0){
    result[arrIndex] = i;
    arrIndex++;
}
}
pending…
contains
var result = [];
var arrIndex = 0;
for(var i = 0; i<l;i++){
if(contains(array,1) < 0){
    result[arrIndex] = i;
    arrIndex++;
}
}
pending…
inArray
var result = [];
var arrIndex = 0;
for(var i = 0; i<l;i++){
if($.inArray(1, array) < 0){
    result[arrIndex] = i;
    arrIndex++;
}
}
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