isNumber (v6)

Revision 6 of this benchmark created by Chris Hoffman on


Preparation HTML

<script>
  var input = 0; // false, 0, 1, '0', '1', 'str'
  var rx = /^\d+\.?\d*$/;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
typeof
(typeof + input === 'number' && input !== false) ? 'true' : 'false';
ready
isNaN
(!isNaN(input) && input !== false) ? 'true' : 'false';
ready
isNaN+parseFloat
!isNaN(parseFloat(input)) ? 'true' : 'false';
ready
isNaN+Number()
!isNaN(Number(input)) ? 'true' : 'false';
ready
regex
rx.test(input);
ready
simple function
if (typeof input === 'number') {
    return true;
}
return (input - 0) == input && input.length > 0;
 
ready
<Infinity
input<Infinity
ready
Math.floor
Math.floor(input)<Infinity
ready
isInteger
Number.isInteger(input)
ready

Revisions

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