Regex Performance

Benchmark created by Dan Voss on


Test runner

Ready to run.

Testing in
TestOps/sec
RegEx Literal
var isValidCode = function(n,minLength,maxLength){
        return /^\+?(0|[1-9]\d*)$/.test(n.toString()) && n.toString().length <= minLength && n.toString().length >= maxLength && 0 === n % (!isNaN(parseFloat(n)) && 0 <= ~~n);
}
isValidCode(555555,6,6);
ready
RegEx Object
var isValidCode = function(n, len) {
        var regEx = "^([0-9]{" + len + "})$",
                re = new RegExp(regEx,"g");
        return re.test(n.toString()) && 0 === n % (!isNaN(parseFloat(n)) && 0 <= ~~n);
}
isValidCode(555555,6);
ready

Revisions

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

  • Revision 1: published by Dan Voss on