C # how to test the code running time,
Method 1:
System. diagnostics. stopwatch stopwatch = new Stopwatch (); stopwatch. start (); // Start to monitor the code running time // code to be tested .... stopwatch. stop (); // Stop monitoring TimeSpan timespan = stopwatch. elapsed; // obtain the total time measured by the current instance. double hours = timespan. totalHours; // total hour double minutes = timespan. totalMinutes; // The total minute double seconds = timespan. totalSeconds; // The total number of seconds. double milliseconds = timespan. totalMilliseconds; // The total number of milliseconds
Method 2:
System. diagnostics. stopwatch watch = new System. diagnostics. stopwatch (); watch. start (); // Start to monitor the code running time // watch the code to be tested. stop (); // Stop monitoring TimeSpan timespan = watch. elapsed; // obtain the total time measured by the current instance System. diagnostics. debug. writeLine ("opening window code execution time: {0} (millisecond)", timespan. totalMilliseconds); // The total number of milliseconds