isNaN vs isNumeric

Benchmark created by dmethvin on


Preparation HTML

<script>
var rdigit = /\d/;
function MYisNaN(n) {
  return n== null || !rdigit.test(n) || isNaN(n);
}

function isNumeric(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
MYisNaN
MYisNaN("-10");
MYisNaN("0");
MYisNaN("5");
MYisNaN(-16);
MYisNaN(0);
MYisNaN(32);
MYisNaN("040");
MYisNaN(0144);
MYisNaN("0xFF");
MYisNaN(0xFFF);
MYisNaN("-1.6");
MYisNaN("4.536");
MYisNaN(-2.6);
MYisNaN(3.1415);
MYisNaN(8e5);
MYisNaN("123e-2");
MYisNaN("");
MYisNaN("        ");
MYisNaN("\t\t");
MYisNaN("abcdefghijklm1234567890");
MYisNaN("xabcdefx");
MYisNaN(true);
MYisNaN(false);
MYisNaN("bcfed5.2");
MYisNaN("7.2acdgs");
MYisNaN(undefined);
MYisNaN(null);
MYisNaN(NaN);
MYisNaN(Infinity);
MYisNaN(Number.POSITIVE_INFINITY);
MYisNaN(Number.NEGATIVE_INFINITY);
MYisNaN(new Date(2009));
MYisNaN({});
MYisNaN(function(){});
ready
isNumeric
isNumeric("-10");
isNumeric("0");
isNumeric("5");
isNumeric(-16);
isNumeric(0);
isNumeric(32);
isNumeric("040");
isNumeric(0144);
isNumeric("0xFF");
isNumeric(0xFFF);
isNumeric("-1.6");
isNumeric("4.536");
isNumeric(-2.6);
isNumeric(3.1415);
isNumeric(8e5);
isNumeric("123e-2");
isNumeric("");
isNumeric("        ");
isNumeric("\t\t");
isNumeric("abcdefghijklm1234567890");
isNumeric("xabcdefx");
isNumeric(true);
isNumeric(false);
isNumeric("bcfed5.2");
isNumeric("7.2acdgs");
isNumeric(undefined);
isNumeric(null);
isNumeric(NaN);
isNumeric(Infinity);
isNumeric(Number.POSITIVE_INFINITY);
isNumeric(Number.NEGATIVE_INFINITY);
isNumeric(new Date(2009));
isNumeric({});
isNumeric(function(){});
ready

Revisions

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

  • Revision 1: published by dmethvin on
  • Revision 4: published by Mikeonthemoon on