if vs else

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
if
function isAlphaNumeric(str) {
  var code, i, len;

  for (i = 0, len = str.length; i < len; i++) {
    code = str.charCodeAt(i);
    if (!(code > 47 && code < 58) && // numeric (0-9)
        !(code > 64 && code < 91) && // upper alpha (A-Z)
        !(code > 96 && code < 123)) { // lower alpha (a-z)
      return false;
    }
  }
  return true;
};
isAlphaNumeric("AASDFWEradsgadfgdfghxcgvdfgadsfrAEWEWRAWE2345234523653456345634563456")
ready
else
function isAlphaNumeric(str) {
  var code, i, len;

  for (i = 0, len = str.length; i < len; i++) {
    code = str.charCodeAt(i);
    if ((code > 47 && code < 58) || // numeric (0-9)
        (code > 64 && code < 91) || // upper alpha (A-Z)
        (code > 96 && code < 123)) { // lower alpha (a-z)
    }else{
    	return false;
    }
  }
  return true;
};
isAlphaNumeric("AASDFWEradsgadfgdfghxcgvdfgadsfrAEWEWRAWE2345234523653456345634563456")
ready
regex
function isAlphaNumeric(str) {
  return /^[A-Za-z0-9]+$/.test(str)
};
isAlphaNumeric("AASDFWEradsgadfgdfghxcgvdfgadsfrAEWEWRAWE2345234523653456345634563456")
ready

Revisions

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