Calculate processing time
1 answer
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 to share