C# code benchmark performance

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have various chunks of code i want to benchmark to see how long they take
to do.

What i'd like to do is check the time at start of code then check time at
end of time to see how long it took. I need better accuracy than just
milliseconds

I'm looking for the time to be very accurate and to give similar results to
the
QueryPerformanceFrequency();
QueryPerformanceCounter();

that i have used in a previous C++ program.

This can give values accurate to microseconds.

Thanks In Advance
Macca
 
You called also do PInvoke and use
QueryPerformanceFrequency();
QueryPerformanceCounter();
 
Hmm, seems i didn't read your question properly, you can replace
TotalMilliSeconds with Ticks to get the result in ticks (computer
cannot be more specific then ticks when time in concerned if i can
remember correctly).
 
ViRi said:
Hmm, seems i didn't read your question properly, you can replace
TotalMilliSeconds with Ticks to get the result in ticks (computer
cannot be more specific then ticks when time in concerned if i can
remember correctly).

Use QueryPerformanceCounter(), I think that's the best you can get
(resolution is microseconds or even less, depending on the
QueryPerformanceFrequency()). You'll have to [DllImport] it though.

hth,
Max
 
Markus said:
Use QueryPerformanceCounter(), I think that's the best you can get
(resolution is microseconds or even less, depending on the
QueryPerformanceFrequency()). You'll have to [DllImport] it though.

It's the best you can get unless you happen to have some special
hardware device installed. Again, if you're using 2.0 the Stopwatch
class basically wraps this API so you only need to [DllImport] if
you're using 1.1 or lower.

Brian
 
Back
Top