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

Revision 13 of this benchmark created by html() vs is() 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
reg
if(/string/i.test(value))alert('YES');
ready
simple
if('string'==value.toLowerCase())alert('YES');
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.