I was actually optimizing Regex transformations of large strings. As some calls to Regex.Replace took significant time I inserted conditional calls - something along the lines
if (str.IndexOf("abc", 0, StringComparison.CurrentCultureIgnoreCase) > 0)
str1 = Regex.Replace(str, "abc...", string.Empty, RegexOptions.IgnoreCase);
To my surprise the results were not convincing. Sometimes better, sometimes not. Or even worse. So I measured performance of case insensitive IndexOf (I tried also StringComparison.OrdinalIgnoreCase) and found that it may be slower than Regex.Match, i.e. this test:
if( Regex.Match(str,"abc", RegexOptions.IgnoreCase).Success )...
Particularly for a large string that did not match (ascii) string "abc" I found that Regex.Match was 4x faster.
Even this procedure is faster than IndexOf:
string s1 = str.ToLower();
if( s1.IndexOf("abc") ) ...
Anybody knows a better solution?