2

I'm wondering if there is a ".net integrated" solution for exact time measurement (like the execution time of a function)? At the moment I'm using the PerformanceCounters from Kernel32.

    [DllImport("Kernel32.dll")]
    private static extern bool QueryPerformanceCounter(
        out long lpPerformanceCount);

    [DllImport("Kernel32.dll")]
    private static extern bool QueryPerformanceFrequency(
        out long lpFrequency);
inspite
  • 27,551
  • 21
  • 73
  • 91
Haiko Wick
  • 387
  • 1
  • 4
  • 12

2 Answers2

12

The Stopwatch is a high resolution framework timer class (that probably wraps that api).

BC.
  • 22,131
  • 12
  • 44
  • 62
  • It appears to be hardware and OS dependent, so it will be high resolution for windows, at least. – BC. Feb 13 '09 at 14:00
3

Try

Both of these work well for finer resolution and straightforward usage.

You could also see

What is the best way to measure execution time of a function?

or

What's the best way to benchmark programs in Windows?

Community
  • 1
  • 1
inspite
  • 27,551
  • 21
  • 73
  • 91