
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 1.06 KB | hits: 13 | expires: Never
static void Main(string[] args)
{
string firstString = "TimeToFigureThisOut";
string secondString = "TIMeToFigREThiSOuT";
bool upperResult;
int compareResult;
Stopwatch compareStopwatch = new Stopwatch();
Stopwatch toUpperStopwatch = new Stopwatch();
// String.Compare
compareStopwatch.Start();
for (int i = 0; i < 10000000; i++)
{
compareResult = string.Compare(firstString, secondString, true);
}
compareStopwatch.Stop();
// ToUpper
toUpperStopwatch.Start();
for (int i = 0; i < 10000000; i++)
{
upperResult = firstString.ToUpper() == secondString;
}
toUpperStopwatch.Stop();
// Results!
Console.WriteLine("Compare took {0} MS!", compareStopwatch.ElapsedMilliseconds);
Console.WriteLine("ToUpper() took {0} MS!", toUpperStopwatch.ElapsedMilliseconds);
}