What is the resolution of cpu time value in ants or dotTrace profiler?

As I understand from my previous research, the resolution timer, if we want to measure cpu time for a function is ~ 15.6ms, we can get the value as

int a=Process.getCurrentProcess.UserProcessTime;
int b=Process.getCurrentProcess.UserProcessTime;
(b-a) //value like 0,15.6,32.2 ms


But using a performance profiler like dotTrace or ant I can see in the time column where the time parameter is "CPU Time" like 4.129; 1.032 ms. This is a high resolution.

What is the way to get this permission by encoding?

functionTest is ==>

    private long FindPrimeNumber(int n)
        int count = 0;
        long a = 2;
        while (count < n)
            long b = 2;
            int prime = 1;// to check if found a prime
            while (b * b <= a)
                if (a % b == 0)
                    prime = 0;
            if (prime > 0)
        return (--a);



source to share

1 answer

You can most likely call native methods in WinAPI from C # via DLLImport. But for simplicity you can try to use the package from here .

But you must clearly understand what you are doing. There will be a difference between the first call to your function and the second due to JITting time. And if your method allocates memory - GC can occur anytime your method is called and it will be reflected in the dimension.



All Articles