我们如何降低 myProcess.TotalProcessorTime 的分辨率? [英] How we can reduce the resolution of myProcess.TotalProcessorTime?

查看:23
本文介绍了我们如何降低 myProcess.TotalProcessorTime 的分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 TotalProcessorTime 通过 cpu 中的方法来测量时间加速.

I'm using TotalProcessorTime to mesure time speding by a method in cpu.

for(int i=0;i<10;i++){
    double s = Process.getCurrentProcess().TotalProcessorTime;
    primeNumber(500);  //return the 500 primenumber 
    doube e = Process.getCurrentProcess().TotalProcessorTime;
    Console.writeLine(e-s);
}

输出如下:015,000115,0001032,0002015,0001015,0001

the output are like: 0 15,0001 15,0001 0 32,0002 0 15,0001 0 15,0001

所以所有输出都为 15,6001 分辨率如此之高.

So All output are mutiliple to 15,6001 the resolution is so hight.

那么我们如何将这个分辨率降低到像 1,2,6,5,2 这样的值?

So How we can reduce this resolution to have values like 1,2,6,5,2 ?

为什么对于相同的代码,它会给出不同的值 0 15,6001 32,0002 ?

And why for the same code it give different values 0 15,6001 32,0002 ?

推荐答案

我几乎可以肯定你会想要使用 StopwatchQueryPerformanceCounter 或类似的东西来满足你的需求.但是TotalProcessorTime的粒度是可以修改的:

I am almost certain you would want to use Stopwatch, QueryPerformanceCounter, or alike for what you desire. However, the granularity of TotalProcessorTime can be modified:

粒度/分辨率由系统计时器分辨率决定.这个 Accurate Windows timer?... 答案显示了如何获取以及如何修改系统计时器分辨率.编码示例在此处 (c) 和 此处 (c#).

The granularity/resolution is determined by the systems timer resolution. This Accurate Windows timer?... answer shows how to obtain and how to modify the systems timer resolution. Coding examples are given here (c) and here (c#).

这篇关于我们如何降低 myProcess.TotalProcessorTime 的分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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