Calculate processing time

I am using C # /. NET 1.1; how can I calculate the processing time, for example to copy a file from one system to another?

+2


source to share


1 answer


System.Diagnostics.Stopwatch

Stopwatch sw = new Stopwatch();
sw.Start();
CopyFile();
sw.Stop();
Console.WriteLine("Elapsed : {0}", sw.Elapsed)

      



This class is not available in .NET 1.1, you can use QueryPerformanceCounter and QueryPerformanceFrequency API instead

[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool QueryPerformanceCounter(out long lpPerformanceCount);

[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool QueryPerformanceFrequency(out long lpFrequency);

...

long start;
long end;
long freq;
QueryPerformanceCounter(out start);
CopyFile();
QueryPerformanceCounter(out end);
QueryPerformanceFrequency(out freq);
double seconds = (double)(end - start) / freq;
Console.WriteLine("Elapsed : {0} seconds", seconds)

      

+15


source







All Articles