RegExp#test vs. String#charCodeAt in a cycle. (v13)

Revision 13 of this benchmark created on


Setup

var shortLorem = 'Lorem';
    var longLorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit.';
    
    var caseSensitiveRegexp = /[A-Za-z,\.]*/;
    var caseInsensitiveRegexp = /[a-z,\.]*/i;
    
    function testCaseSensitiveRegExp(input) {
      return caseSensitiveRegexp.test(input);
    }
    
    function testCaseInsensitiveRegExp(input) {
      return caseInsensitiveRegexp.test(input);
    }
    
    function testCharCodeAt(input) {
      for (var index = 0, length = input.length; index < length; index += 1) {
        var code = input.charCodeAt(index);
    
        if (!((65 <= code && code <= 90) ||
              (97 <= code && code <= 122) ||
              (44 !== code) ||
              (46 !== code))) {
          return false;
        }
      }
    
      return true;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
RegExp (short input, case sensitive)
testCaseSensitiveRegExp(shortLorem);
ready
RegExp (short input, case insensitive)
testCaseInsensitiveRegExp(shortLorem);
ready
charCodeAt in a cycle (short input)
testCharCodeAt(shortLorem);
ready
RegExp (long input, case sensitive)
testCaseSensitiveRegExp(longLorem);
ready
RegExp (long input, case insensitive)
testCaseInsensitiveRegExp(longLorem);
ready
charCodeAt in a cycle (long input)
testCharCodeAt(longLorem);
ready

Revisions

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