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

Revision 8 of this benchmark created on


Description

Comparing string startsWith ignoring case, with RegExp counterpart

Setup

var value = 'StRinG',
      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()
match = (value.toLowerCase() == ("string".toLowerCase()))
ready
toUpperCase()
match = (value.toUpperCase() == "string".toUpperCase())
ready

Revisions

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