isnan

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [1,2,3,4,5,6,7,8,'a'];
   
    function some() {
      return !Array.prototype.some.call(a,function(i){
        return typeof i != 'number';
      });
    }
   
    function for1() {
      for(var i=a.length;i--;) {
        if(typeof a[i] != 'number') return false;
      }
      return true;
    }
   
    function someisnan() {
      return !Array.prototype.some.call(a,isNaN);
    }
   
    function for2() {
      var i=a.length;
      while(i--) {
        if(typeof a[i] != 'number') return false;
      }
      return true;
    }
   
    function for3() {
    var i;
      while(i=a.shift()|| a.length) {
        if(typeof i != 'number') return false;
      }
      return true;
    }
};
</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
some
some();
pending…
for
for1()
pending…
for2
for2()
pending…
for3
for3();
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