string src = "abcd";
string dest = "ABCD";
int maxIter = 10000;
int matchCount = 0;
Stopwatch sw = Stopwatch.StartNew();
matchCount = 0;
for (int i = 0; i < maxIter; i++)
{
if (src.ToLower() == dest.ToLower())
matchCount++;
}
sw.Stop();
if (matchCount != maxIter)
return;
Console.WriteLine("Lower Equal " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew();
matchCount = 0;
for (int i = 0; i < maxIter; i++)
{
if (src.ToUpper() == dest.ToUpper())
matchCount++;
}
sw.Stop();
if (matchCount != maxIter)
return;
Console.WriteLine("Upper Equal " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew();
matchCount = 0;
for (int i = 0; i < maxIter; i++)
{
if (src.Equals(dest, StringComparison.InvariantCultureIgnoreCase))
matchCount++;
}
sw.Stop();
if (matchCount != maxIter)
return;
Console.WriteLine("StringComparison.Ordinal InvariantCultureIgnoreCase " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew();
matchCount = 0;
for (int i = 0; i < maxIter; i++)
{
if (src.Equals(dest, StringComparison.CurrentCultureIgnoreCase))
matchCount++;
}
sw.Stop();
if (matchCount != maxIter)
return;
Console.WriteLine("StringComparison.Ordinal CurrentCultureIgnoreCase " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew();
matchCount = 0;
for (int i = 0; i < maxIter; i++)
{
if (src.Equals(dest, StringComparison.OrdinalIgnoreCase))
matchCount++;
}
sw.Stop();
if (matchCount != maxIter)
return;
Console.WriteLine("StringComparison.Ordinal OrdinalIgnoreCase " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew();
matchCount = 0;
for (int i = 0; i < maxIter; i++)
{
if (string.Compare(src, dest, true) == 0)
matchCount++;
}
sw.Stop();
if (matchCount != maxIter)
return;
Console.WriteLine("string.Compare Ignore " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew();
matchCount = 0;
for (int i = 0; i < maxIter; i++)
{
if (string.CompareOrdinal(src.ToLower(), dest.ToLower()) == 0)
matchCount++;
}
sw.Stop();
if (matchCount != maxIter)
return;
Console.WriteLine("string.CompareOrdinal ToLower " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew();
matchCount = 0;
for (int i = 0; i < maxIter; i++)
{
if (string.CompareOrdinal(src.ToUpper(), dest.ToUpper()) == 0)
matchCount++;
}
sw.Stop();
if (matchCount != maxIter)
return;
Console.WriteLine("string.CompareOrdinal ToUpper " + sw.Elapsed.ToString());
|