The benchmark shows that you can improve performance by using a CultureInfo.CurrentCulture.TextInfo variable and calling the instance ToLower method on it.
using System;
using System.Diagnostics;
using System.Globalization;
class Program
{
const int _max = 1000000;
static void Main()
{
TextInfo textInfo = CultureInfo.CurrentCulture.TextInfo;
var s1 = Stopwatch.StartNew();
// Version 1: use TextInfo ToLower.
for (int i = 0; i < _max; i++)
{
string lower = textInfo.ToLower(
"GRAYCAT");
}
s1.Stop();
var s2 = Stopwatch.StartNew();
// Version 2: use String method.
for (int i = 0; i < _max; i++)
{
string lower =
"GRAYCAT".ToLower();
}
s2.Stop();
Console.WriteLine(((double)(s1.Elapsed.TotalMilliseconds * 1000000) / _max).ToString(
"0.00 ns"));
Console.WriteLine(((double)(s2.Elapsed.TotalMilliseconds * 1000000) / _max).ToString(
"0.00 ns"));
}
}
29.88 ns TextInfo ToLower
40.72 ns String ToLower