regex vs for loop (v12)

Revision 12 of this benchmark created on


Preparation HTML

<script>

  var reg_vowels = new RegExp("[aeiou]");
  function isVowelRegEx(char) {
   
    return reg_vowels.test(char);
   
  }
  
  var vowels = new Array('a', 'e', 'i', 'o', 'u');
  
  function isVowel(char) {
   if (char.length === 1) {
    var len = vowels.length;
    for (var i = 0; i < len; i++) {
     if (vowels[i] === char) {
      return true;
     }
    }
    return false;
   }
  }
  
  var vowelsindex = "aeiou";
  
  function isVowelindex(char) {
   if (char.length === 1) {
    return vowelsindex.indexOf(char) >= 0 ? true : false;
   }
  }


  function isVowelChars(char) {
    return char === 'a' || char === 'e' || char === 'i' || char === 'o' || char === 'u' || false;
  }    
 function isVowelIndexOf(char) {
    return 1 === char.length && ("aeiou".indexOf(char) !== -1);
}


</script>

Test runner

Ready to run.

Testing in
TestOps/sec
regex
isVowelRegEx('a');
isVowelRegEx('v');
isVowelRegEx('u');
ready
for loop
isVowel('a');
isVowel('v');
isVowel('u');
ready
index
isVowelindex('a');
isVowelindex('v');
isVowelindex('u');
ready
chars
isVowelChars('a');
isVowelChars('v');
isVowelChars('u');
ready
indexof
isVowelIndexOf('a');
isVowelIndexOf('v');
isVowelIndexOf('u');
ready

Revisions

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