StopWatch class is used for calculate, the timespan for that procedure. In Debug Mode It'll be very useful.
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Diagnostics;6 7 namespacestopwatchtest8 {9 class ProgramTen { One Static voidMain (string[] args) A { -Stopwatch SW =NewStopwatch (); - strings =string. Empty; theStringBuilder SB =NewStringBuilder (); - Const intTicks =100000; - SW. Start (); - for(inti =0; I < ticks; i++) S + ="a"; + SW. Stop (); -TimeSpan ts =SW. Elapsed; +Console.WriteLine ("string Append ' a ' {0} times using time in time: {1}, in MilliSeconds: {2}, ticks: {3}", ticks. ToString (), TS. ToString (), ts.Milliseconds.ToString (), TS. Ticks.tostring ()); A SW. Restart (); at for(inti =0; I < ticks; i++) sb. Append ("a"); - SW. Stop (); - //ts = sw. Elapsed; -Console.WriteLine ("StringBuilder Append ' a ' {0} times using time in time: {1}, in MilliSeconds: {2}, ticks: {3}", ticks. ToString (), SW. Elapsed.tostring (), SW. Elapsedmilliseconds.tostring (), SW. Elapsedticks.tostring ()); - } - } in}
. net:c#: StopWatch