Haiko Wick
Haiko Wick

Reputation: 417

C# replacement for PerformanceCounter

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);

Upvotes: 2

Views: 1110

Answers (2)

Ian G
Ian G

Reputation: 30224

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?

Upvotes: 3

BC.
BC.

Reputation: 24908

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

Upvotes: 12

Related Questions