isalpha-z

Benchmark created on


Description

Just like http://jsperf.com/isalpha but the test character is 'z'.

Preparation HTML

<script>
  var alphaRe = /[a-zA-Z]/;
  
  var alphaChars = '';
  for (i = 'A'.charCodeAt(0); i <= 'Z'.charCodeAt(0); i += 1) {
   alphaChars += String.fromCharCode(i);
  }
  for (i = 'a'.charCodeAt(0); i <= 'z'.charCodeAt(0); i += 1) {
   alphaChars += String.fromCharCode(i);
  }
  
  // eval to prevent constant-folding optimization
  var ch = eval('"z"');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
if
var y = ((ch >= 'a') && (ch <= 'z')) || ((ch >= 'A') && (ch <= 'Z'));
ready
indexOf
var z = alphaChars.indexOf(ch) !== -1;
ready
regex
var x = !! ch.match(alphaRe);
ready

Revisions

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