regex vs for loop (v14)

Revision 14 of this benchmark created by Muhamed on


Preparation HTML

<script>
  function isVowelRegEx(char) {
   if (char.length === 1) {
    return /[aeiou]/.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;
   }
  }

var vowels = ['a', 'e',  'i',  'o',  'u'];
function vowelIndexOfArray(char) {

	if (char.length === 1) {
		if (vowels.indexOf(char) > 0) {
			return true;
		}
	}

	return false;
}



</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
VowelIndexOfArray
vowelIndexOfArray('a');
vowelIndexOfArray('v');
ready

Revisions

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