regex vs toLowerCase() (v5)

Revision 5 of this benchmark created on


Description

perf difference between running a string through .toLowerCase() before applying a regex or just doing it in the regex.

Setup

var testString = "iPhone";
    
    var r = "PH";
    
    var searchValue = r.replace(/[a-z]+/i, '' )

Test runner

Ready to run.

Testing in
TestOps/sec
regex
var r = /PH/i;

var match = ~testString.search(r);
ready
.toLowerCase() first
var r = "PH";
var match = ~testString.toLowerCase().indexOf(r.toLowerCase());
ready
escaped regex one replace
var match = ~testString.search(~searchValue );
ready

Revisions

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