Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.06 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. static void Main(string[] args)
  2.         {
  3.             string firstString = "TimeToFigureThisOut";
  4.             string secondString = "TIMeToFigREThiSOuT";
  5.             bool upperResult;
  6.             int compareResult;
  7.  
  8.             Stopwatch compareStopwatch = new Stopwatch();
  9.             Stopwatch toUpperStopwatch = new Stopwatch();
  10.  
  11.             // String.Compare
  12.             compareStopwatch.Start();
  13.             for (int i = 0; i < 10000000; i++)
  14.             {
  15.                 compareResult = string.Compare(firstString, secondString, true);
  16.             }
  17.             compareStopwatch.Stop();
  18.  
  19.             // ToUpper
  20.             toUpperStopwatch.Start();
  21.             for (int i = 0; i < 10000000; i++)
  22.             {
  23.                 upperResult = firstString.ToUpper() == secondString;
  24.             }
  25.             toUpperStopwatch.Stop();
  26.  
  27.             // Results!
  28.             Console.WriteLine("Compare took {0} MS!", compareStopwatch.ElapsedMilliseconds);
  29.             Console.WriteLine("ToUpper() took {0} MS!", toUpperStopwatch.ElapsedMilliseconds);
  30.         }