views:

43

answers:

2

I am writing a program that needs to run a set of executables and find their execution times. My first approach was just to run a process, start a timer and see the difference between the start time and the moment when process returns exit value.

Unfortunately, this program will not run on the dedicated machine so many other processes / threads can greatly change the execution time.

I would like to get time in milliseconds / clocks that actually was given to the process by OS. I hope that windows stores that information somewhere but I cannot find anything useful on the msdn.

Sure one solution is to run the process multiple times and calculate the avrage time, but I wont to avoid that.

Thanks.

+1  A: 

The "High-Performance Counter" might be what you're looking for.

I've used QueryPerformanceCounter/QueryPerformanceFrequency for high-resolution timing in stuff like 3D programming where the stock functionality just doesn't cut it.

You could also try the RDTSC x86 instruction.

Matthew Iselin
Thanks, but I don't really need a higher resolution, I just need the exact time (ms are OK) that were given to the process.
Klark
@Klark: Fair enough. The high-performance counters can be converted into time values (that's what QueryPerformanceFrequency is there for), but Naveen's answer is much easier and simpler.
Matthew Iselin
+2  A: 

You can take a look at GetProcessTimes API.

Naveen
You mean GetProcessTimes.
ybungalobill
Yep, the GetProcessTimes is what I was looking for.
Klark
Yes..updated accordingly.
Naveen