number type

JavaScript performance comparison

Test case created by Andreas Deuschlinger

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var isIntOR = function( n ) {
    n===+n && n===(n|0);
    };
   
    var isIntP = function( n ) {
    n===Number(n) && n===parseInt(n);
    };
   
    var isFloatOR = function( n ) {
    n===+n && n!==(n|0);
    };
   
    var isFloatP = function( n ) {
    n===Number(n) && n!==parseInt(n);
    };
   
    var isIntM = function(n) {
       return ((typeof n==='number')&&(n%1===0));
    }
   
    var isFloatM = function(n) {
       return ((typeof n==='number')&&(n%1!==0));
    }
};
</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
Int OR
var n = Math.random() * 1000;
isIntOR( n );
pending…
Int Parse
var n = Math.random() * 1000;
isIntP( n );
pending…
Float OR
var n = Math.random() * 1000;
isFloatOR( n );
pending…
Float Parse
var n = Math.random() * 1000;
isFloatP( n );
pending…
Int Modulo
var n = Math.random() * 1000;
isIntM( n );
pending…
Float Modulo
var n = Math.random() * 1000;
isFloatM( n );
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