How we can reduce the resolution of myProcess.Tota

2019-01-28 13:33发布

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

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

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

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

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

1条回答
贪生不怕死
2楼-- · 2019-01-28 13:59

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:

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#).

查看更多
登录 后发表回答