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

Revision 12 of this benchmark created on


Description

Comparing string startsWith ignoring case, with RegExp counterpart

Preparation HTML

<input id="target">

Setup

var value = 'StRinG',
        match,
        pw1 = 'password',
        pw2 = 'PASSWORD';
    var field = document.querySelectorAll('input');

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
1 .test
(/password/i).test(field[0].type + ' ' + field[0].name)
ready
2 .test
(/password/i).test(field[0].type)||(/password/i).test(field[0].name)
ready

Revisions

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