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

Revision 10 of this benchmark created by HItesh Aneja on


Description

Out of curiosity, I wanted to know what would be faster; running a case insensitive regular expression, on a string, or converting the string to lower/upper case and running a normal, case sensitive regular expression.

Setup

var value = 'This iS a StRinG!',
        value2 = "this is a string",
        match;

Test runner

Ready to run.

Testing in
TestOps/sec
Case insensitive regular expression
match = /string/i.test(value);
ready
toLowerCase() and case sensitive regular expression
match = /string/.test(value.toLowerCase());
ready
toUpperCase() and case sensitive regular expression
match = /STRING/.test(value.toUpperCase());
ready
Simple string match
//match = value == 'string';
ready
Multiple single string matches
//match = (value == 'string') || (value == 'STRING');
ready
toUpperCase() string comparison
//match = (value.toUpperCase() === value2.toUpperCase())
match = new RegExp(value, "i").test(value2)
ready

Revisions

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