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

Revision 4 of this benchmark created 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!',
        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

Revisions

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