numeric checks

JavaScript performance comparison

Test case created

Info

simple numeric checks

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function isNumber1(n) {
      return !isNaN(parseFloat(n)) && isFinite(n);
    }
   
    function isNumber2(n) {
      return !isNaN(n) && isFinite(n);
    }
   
    function isNumber3(n) {
      return /^[0-9]+$/.test(n);
    }
   
    var r1 = /^[0-9]+$/;
    var r2 = new RegExp("^[0-9]+$");
   
    function isNumber4(n) {
      return r1.test(n);
    }
   
    function isNumber5(n) {
      return r2.test(n);
    }
   
   
};
</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
isNaN / parseFloat / isFinite
isNumber1(12);
isNumber1("34");
isNumber1({});
pending…
isNaN / isFinite
isNumber2(12);
isNumber2("34");
isNumber2({});
pending…
literal regex
isNumber3(12);
isNumber3("34");
isNumber3({});
pending…
cached literal regex
isNumber4(12);
isNumber4("34");
isNumber4({});
pending…
cached RegExp object
isNumber5(12);
isNumber5("34");
isNumber5({});
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. Here’s a list of current revisions for this page:

0 comments

Add a comment