Test is string number

Benchmark created on


Setup

const isNumericTest = n => /^\d+$/.test(n);
const isNumericFloat = n => !isNaN(parseFloat(n));
const isNumericInt = n => !isNaN(parseInt(n));
const isNumericTypeof = n => typeof n === "number";

Test runner

Ready to run.

Testing in
TestOps/sec
isNumericTest
for (let i = 0; i < 10; ++i) {
	const test = i % 2 ? String(i) : "abc";
	isNumericTest(test)
}
ready
isNumericFloat
for (let i = 0; i < 10; ++i) {
	const test = i % 2 ? String(i) : "abc";
	isNumericFloat(test)
}
ready
isNumericInt
for (let i = 0; i < 10; ++i) {
	const test = i % 2 ? String(i) : "abc";
	isNumericInt(test)
}
ready
isNumericTypeof
for (let i = 0; i < 10; ++i) {
	const test = i % 2 ? String(i) : "abc";
	isNumericTypeof(test)
}
ready

Revisions

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