regex vs for loop (v8)

Revision 8 of this benchmark created on


Preparation HTML

<script>

  var reg_vowels = new RegExp("[aeiou]");
  function isVowelRegEx(char) {
   if (char.length === 1) {
    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;
   }
  }
</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

Revisions

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