Number && isInteger vs Regex (v3)

Revision 3 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
parseInt && isInteger
const isDecimal = (val) => Number.isInteger(Number(val))

isDecimal('foo')
isDecimal('100.00.00')
isDecimal('100.00')
isDecimal('100')
ready
Regex
const isDecimal = (val) => /^\d+(\.\d+)?$/.test(val)

isDecimal('foo')
isDecimal('100.00.00')
isDecimal('100.00')
isDecimal('100')
ready
Regex with cached regex
const regexp = new RegExp(/^\d+(\.\d+)?$/)

const isDecimal = (val) => regexp.test(val)

isDecimal('foo')
isDecimal('100.00.00')
isDecimal('100.00')
isDecimal('100')
ready
Regex tested directly
const regexp = new RegExp(/^\d+(\.\d+)?$/)

regexp.test('foo')
regexp.test('100.00.00')
regexp.test('100.00')
regexp.test('100')
ready

Revisions

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