Omega
Omega

Reputation: 1599

why UserProcessorTime don't give the same value for the same executions

I'm measuring just cpu time of the a method but it give me different time why ?

 for (int i = 0; i < 10; i++){
TimeSpan start = Process.GetCurrentProcess().UserProcessorTime;
testFunction(100000);
TimeSpan end = Process.GetCurrentProcess().UserProcessorTime;
Console.WriteLine(end-start);
}

Upvotes: 0

Views: 511

Answers (1)

Disappointed
Disappointed

Reputation: 1120

Function execution time depends on a lot of things: number of running processes at current time(which can be changed during loop execution), priority of your process(which as i know also can be changed), OS interrupts during function execution, RAM (for example RAM page fault) etc. So it's nothing strange if execution time differs a little from time to time.

Upvotes: 2

Related Questions