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 ?
I am almost certain you would want to use
Stopwatch
,QueryPerformanceCounter
, or alike for what you desire. However, the granularity ofTotalProcessorTime
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#).