usingSystem;usingSystem.Diagnostics;usingSystem.Runtime.InteropServices;usingSystem.Threading;classprogram{//Calling API Functions[DllImport ("Kernel32.dll")] extern Static ShortQueryPerformanceCounter (ref Longx); [DllImport ("Kernel32.dll")] extern Static ShortQueryPerformanceFrequency (ref Longx); Static voidMain (string[] args) { //Method OneStopwatch Stopwatch =NewStopwatch (); Stopwatch.start (); Thread.Sleep ( +); Stopwatch.stop (); LongTimes1 =Stopwatch.elapsedmilliseconds; Console.WriteLine ("RunTime"+times1); //Method Two LongStop_value =0; LongStart_value =0; LongFreq =0; QueryPerformanceFrequency (refFREQ);//Get CPU FrequencyQueryPerformanceCounter (refStart_value);//get initial pre-valueThread.Sleep ( +); QueryPerformanceCounter (refStop_value);//get the value of the terminating variable varTimes2 = (stop_value-start_value)/(Double) Freq * +; Console.WriteLine ("RunTime"+Times2); }}
C # Timing function (MS)