ant 或 dotTrace profiler 中 CPU 时间值的分辨率是多少? [英] What is the resolution of the CPU time value in ants or dotTrace profiler?

查看:63
本文介绍了ant 或 dotTrace profiler 中 CPU 时间值的分辨率是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从我之前的研究中了解到,如果我们想测量一个函数的 CPU 时间,分辨率计时器是 ~15.6 毫秒,这意味着我们可以获得 0、15.6、32.2 毫秒之类的值

As I understand from my previous research the resolution timer if we want to measure CPU time of a function is ~15.6ms mean we can get value like 0,15.6,32.2 ms

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

但是使用像 dotTrace 或 ant 这样的性能分析器,我在时间列中看到,其中计时选项是CPU 时间"值,例如 4.129;1.032 ms 所以这是一个高分辨率.

But using performance profiler like dotTrace or ant I see in time column where timing option is "CPU Time" value like 4.129; 1.032 ms So it's a high resolution.

通过编码得到这个分辨率的方法是什么?

What is the method to get this resolution by coding?

functionTest 是 ==>

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;
                    break;
                }
                b++;
            }
            if (prime > 0)
                count++;
            a++;
        }
        return (--a);
    }

推荐答案

它很可能是 WinAPI 中的本机方法,您可以通过 DLLImport 从 C# 调用它们.但为简单起见,您可以尝试使用 此处 中的第三方包装器.

It's native methods in WinAPI most likely, you can invoke them from C# via DLLImport. But for simplicity you could try use third party wrapper from here.

但是你应该清楚地了解你在做什么.由于 JITting 时间,您的函数的第一次调用和第二次调用之间会有所不同.如果您的方法分配了内存 - GC 可能会在调用您的方法时随时发生,并且会反映在测量中.

But you should clearly understand what you are doing. Between first call of your function and the second one will be difference because of JITting time. And if your method allocates memory - GC might occur any time while calling your method and it will be reflected in measurement.

这篇关于ant 或 dotTrace profiler 中 CPU 时间值的分辨率是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆