isNumber-with-typeof

JavaScript performance comparison

Test case created by seb

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function isNumber(obj) {
    return Object.prototype.toString.call(obj) == '[object Number]'
  }
  
  function isNumberFast(obj) {
    if (typeof obj == 'number') return true;
    return Object.prototype.toString.call(obj) == '[object Number]'
  }
  
  function isNumberFaster(obj) {
    if (typeof obj == 'number') return true;
    if (typeof obj != 'object') return false;
    return Object.prototype.toString.call(obj) == '[object Number]'
  }
  

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
isNumber( 1 )
isNumber( 1 )
pending…
isNumberFast( 1 )
isNumberFast( 1 )
pending…
isNumberFaster( 1 )
isNumberFaster( 1 )
pending…
isNumberFaster( "foo" )
isNumberFaster( "foo" )
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.

0 Comments