number type
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
Int OR |
|
pending… |
Int Parse |
|
pending… |
Float OR |
|
pending… |
Float Parse |
|
pending… |
Int Modulo |
|
pending… |
Float Modulo |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments