if vs else (v3)

Revision 3 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
regex
function isAlphaNumeric(str) {
  return /^[A-Za-z0-9\ \-]+$/.test(str)
};
isAlphaNumeric("AASDFWEradsgadfgdfghxcgvdfgadsfrAEWEWRAWE23452345236534563456 -34563456")
ready
non-regex
function isAlphaNumeric(str) {
  let char = "";
  for (let i = 0, len = str.length; i < len; i++) {
    char = str[i];
    if ((char >= "0" && char <= "9") || // numeric (0-9)
        (char >= "A" && char <= "Z") || // upper alpha (A-Z)
        (char >= "a" && char <= "z") || // lower alpha (a-z)
        (char == " " || char == "-")){ // special chars
    }else{
    	return false;
    }
  }
  return true;
};
isAlphaNumeric("AASDFWEradsgadfgdfghxcgvdfgadsfrAEWEWRAWE2345234523653456 -345634563456")
ready

Revisions

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