我们怎样才能减少myProcess.TotalProcessorTime的分辨率是多少? [英] How we can reduce the resolution of myProcess.TotalProcessorTime?

查看:132
本文介绍了我们怎样才能减少myProcess.TotalProcessorTime的分辨率是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用TotalProcessorTime到mesure在CPU的方法时间speding

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



输出是这样的:
0
15, 0001
15,0001
0
32,0002
0
15,0001
0
15,0001

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

所以,所有的输出都mutiliple至15,6001分辨率是如此之HIGHT。

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 ?

推荐答案

我几乎可以肯定你想使用秒表 QueryPerformanceCounter的,或都为你的愿望。然而, 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:

粒度/分辨率由系统定时分辨率决定。
准确的Windows计时器?...... 回答了如何获取和如何修改系统计时器的分辨率。编码的例子在这里给出(三)和的这里(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天全站免登陆