开发者

Getting CPU time spent on process vs. World time spent on process problem c++

I am usin开发者_运维百科g two different ways of obtaining time clock() and getLocalTime() because I Want both the CPU time spent on my process AND the wall clock time spent on this process. Currently I do this:

printf("CPU Time: %gms \n", (((double)(finish-start)) / CLOCKS_PER_SEC)*1000.0);
printf("Clock Time: %ldms \n", (end.sec-begin.sec)*1000+(end.msec-begin.msec));

but they are both giving me the same exact result! (on something running ~30 seconds) and I know for the fact the CPU is not spending that much time on the process. Am I using the correct functions? Thanks.


On Unix systems, CPU time can be obtained by getrusage().


No really cross platform, but on Windows there are two possibilities:

  • GetProcessTimes(): returns time spent by the process in kernel mode and user mode
  • QueryProcessCycleTime(): returns the number of CPU cycles spent by the process (requires Windows Vista).

Haven't used them myself, but I believe that both would give the same results


clock() isn't the right tool for portable elapsed time. Under windows, it is defined to return the elapsed wall time, on unix type systems, it returns the elapsed processor time.

I'm sure there must be a portable solution, I'm not sure where to look though. I'd hunt through boost for a start.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜