Is it a number?

Benchmark created by John Cockrell on


Description

What's the fastest way to tell if something is a number?

Setup

var Underscore = {};
    var BELT = {},
        num = 500,
        pnum = "500";
    
    BELT.isNumber = function(it) {
       return typeof it === 'number';
    };
    
    Underscore.isNumber = function(it) {
       return toString.call(it) == '[object ' + name + ']';
    }

Test runner

Ready to run.

Testing in
TestOps/sec
BELT typeof
BELT.isNumber(num);
BELT.isNumber(pnum);
ready
Underscore
Underscore.isNumber(num);
Underscore.isNumber(pnum);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by John Cockrell on