Testing number with parseInt or RegExp

Benchmark created by slns on


Setup

var num1 = "123";
    var num2 = "123abcdef";
    var num3 = "abcdef123";
    var regexp = /^\d/;

Test runner

Ready to run.

Testing in
TestOps/sec
RegExp (inline)
/^\d/.test(num1);
/^\d/.test(num2);
/^\d/.test(num3);
 
ready
RegExp (predefined)
regexp.test(num1);
regexp.test(num2);
regexp.test(num3);
ready
parseInt
!isNaN(parseInt(num1, 10));
!isNaN(parseInt(num2, 10));
!isNaN(parseInt(num3, 10));
ready

Revisions

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