The first way:
System.Diagnostics.Stopwatch Stopwatch =NewStopwatch (); Stopwatch. Start (); //Start monitoring code run time//code that needs to be tested ....Stopwatch. Stop ();//Stop MonitoringTimeSpan timespan = stopwatch. Elapsed;//gets the total time measured by the current instanceDoubleHours = TimeSpan. TotalHours;//Total HoursDoubleminutes = TimeSpan. Totalminutes;//Total minutesDoubleseconds = TimeSpan. TotalSeconds;//total number of secondsDoublemilliseconds = TimeSpan. TotalMilliseconds;//total number of milliseconds
The second way:
New System.Diagnostics.Stopwatch (); watch. Start (); // Start monitoring code run time // code watch that needs to be tested . Stop (); // Stop Monitoring TimeSpan timespan = Watch. Elapsed; // gets the total time measured by the current instance System.Diagnostics.Debug.WriteLine (" open Window Code execution time: {0} (milliseconds)", TimeSpan. TotalMilliseconds); // total number of milliseconds
How C # Tests code run time