charcodeat loop vs regex

Benchmark created on


Setup

const value = "this is a long alphanumerical value 9Zz";

Test runner

Ready to run.

Testing in
TestOps/sec
charcode at looü
for (let i = 0; i < value.length; i++) {
    const code = value.charCodeAt(i);
    if (!((code > 47 && code < 58) || (code > 64 && code < 91) || (code > 96 && code < 123))) {
        return false;
    }
}
return true;
ready
regex
const alphanumericRegex = /^[a-zA-Z0-9]+$/;
return alphanumericRegex.test(value);
ready

Revisions

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