Getting CPU time spent on a process versus world time spent on a C ++ process problem

I use two different ways to get the time clock () and getLocalTime (), because I want both the processor time spent on my process and the wall clock time spent on this process. I am currently doing 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 both give me the exact same result! (~ 30 seconds work on something), and I know that the processor does not spend so much time on the process. Am I using the correct functions? Thank.

+3
source share
3 answers

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

+1
source

There is no cross platform, but on Windows there are two possibilities:

, ,

+1

clock()is not a suitable tool for portable elapsed time. Under the windows it is determined that the elapsed time return time, on unix systems, returns the elapsed processor time.

I'm sure there should be a portable solution, I'm not sure where to look. I would hunt forcing to start.

0
source

Source: https://habr.com/ru/post/1790543/


All Articles