IsUpper Speed Comparison (v8)

Revision 8 of this benchmark created by mina86 on


Setup

var ucLetters1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
      check1 = /[a-z]/;
  Util = {
    /**
     * @return true if ch is a upper-case letter
     */
    isUpper : function (ch) {
      ch = ch.charCodeAt(0);
      return ch >=65 && ch <= 90;
    },
  
    isUpper2: function (ch) {
      var ucLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      return ucLetters.indexOf(ch) != -1;
    },
  
    isUpper21: function (ch) {
      return ucLetters1.indexOf(ch) != -1;
    },
  
    isUpper3: function(ch) {
      return ch.toUpperCase() === ch;
    },
  
    isUpper4: function(ch) {
      var check = /[a-z]/;
      return check.test(ch);
    },
  
    isUpper41: function(ch) {
      return check1.test(ch);
    },
  }
  
  var c = "hello".charAt(0);

Test runner

Ready to run.

Testing in
TestOps/sec
isUpper
Util.isUpper(c)
ready
isUpper2
Util.isUpper2(c)
ready
isUpper21
Util.isUpper21(c)
ready
isUpper3
Util.isUpper3(c)
ready
isUpper4
Util.isUpper4(c)
ready
isUpper41
Util.isUpper41(c)
ready

Revisions

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