regex vs for loop (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
  var regex = /[aeiou]/;
  
  function isVowelRegEx(char) {
   if (char.length === 1) return regex.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 isSimpleVowel(char) {
   if (char.length === 1) return char === 'a' || char === 'e' || char === 'i' || char === 'o' || char === 'u';
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
regex
isVowelRegEx('a');
isVowelRegEx('v');
ready
for loop
isVowel('a');
isVowel('v');
ready
index
isVowelindex('a');
isVowelindex('v');
ready
expression
isSimpleVowel('a');
isSimpleVowel('v');
ready

Revisions

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