Case insensitive regex vs toLowerCase() then regex (v7)

Revision 7 of this benchmark created by Magnus on


Description

Comparing string startsWith ignoring case, with RegExp counterpart

Setup

var value = 'StRinG this iS!',
        match;
    
    // startsWith polyfill
    if (typeof String.prototype.startsWith != 'function') {
      String.prototype.startsWith = function (str){
        return this.slice(0, str.length) === str;
      };
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Case insensitive regular expression
match = /^string/i.test(value);
ready
toLowerCase() and startsWith
match = value.toLowerCase().startsWith("string".toLowerCase());
ready
toUpperCase() and startsWith
match = value.toUpperCase().startsWith("string".toUpperCase());
ready

Revisions

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