~indexof-1

JavaScript performance comparison

Test case created

Preparation code

<script>var testArray=[],testSearch=[];
for(var i = 0;i<10000;i++){
  testArray.push(Math.ceil(Math.random()*10000));
}

for(var i = 0;i<1000;i++){
  testSearch.push(testArray[Math.floor(Math.random()*10000)]);
}
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
indexOf > -1
var c = 0;
for(var l=testSearch.length;--l;){
  if( testArray.indexOf(testSearch[l]) > -1 ){
   c++;
  }
}
 
pending…
~indexOf
var c = 0;
for(var l=testSearch.length;--l;){
  if( ~testArray.indexOf(testSearch[l]) ){
   c++;
  }
}
 
pending…

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

Compare results of other browsers

0 comments

Add a comment