StopWatch 学习

StopWatch string类型的==与 String.Compare()比较
笔记:
private void StopWatchT_Load( object sender, EventArgs e)
{
          Stopwatch stopWatch = new Stopwatch();
          string str1 = @"aasadflkjfowejlkmvxzclkvjojweoru923847j(*&(Uo4123-41234143-5=-4-9=435\=34532452734";
           string str2 = @"aasadflkjfowejlkmvxzclkvjojweoru923847j(*&(Uo4123-41234143-5=-4-9=435\=34532452734";
           int result = 0;

           stopWatch.Start();

          for ( int i = 0; i < 10000000; i++)
           {
                     result = String.Compare(str1, str2);
           }

             stopWatch.Stop();

            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch.Elapsed;

             // Format and display the TimeSpan value.
            string elapsedTime = String.Format( "{0:00}:{1:00}:{2:00}.{3:00}",
            ts.Hours, ts.Minutes, ts.Seconds,
            ts.Milliseconds / 10);

            lblResult.Text = "Result:" + result.ToString();

             lblTime.Text = "RunTime:" + elapsedTime;

            stopWatch = Stopwatch.StartNew();

             stopWatch.Start();

            for ( int i = 0; i < 1000000; i++)
            {
                      if (str1 == str2)
                              result = 0;
                      else
                              result = 1;
             }

            stopWatch.Stop();

             // Get the elapsed time as a TimeSpan value.
             TimeSpan t = stopWatch.Elapsed;

              // Format and display the TimeSpan value.
              string et = String.Format( "{0:00}:{1:00}:{2:00}.{3:00}",
                                t.Hours, t.Minutes, t.Seconds,
                                t.Milliseconds / 10);

               lblResult2.Text = "Result:" + result.ToString();

               lblTime2.Text = "RunTime:" + et;
}


你可能感兴趣的:(.net,String,C#,==,stopwatch)