Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate processing time

Tags:

c#

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

like image 936
maxy Avatar asked Jul 10 '26 12:07

maxy


1 Answers

System.Diagnostics.Stopwatch

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

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

[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)
like image 174
Thomas Levesque Avatar answered Jul 12 '26 02:07

Thomas Levesque



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!