3

I am using 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.

Pete L
  • 61
  • 1
  • 3

3 Answers3

1

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

DS.
  • 22,632
  • 6
  • 47
  • 54
  • Right now I'm on windows and it was working fine on Linux, I'm not sure why it isn't cooperating. – Pete L Feb 07 '11 at 20:34
1

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

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

CharlesB
  • 86,532
  • 28
  • 194
  • 218
0

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.

ergosys
  • 47,835
  • 5
  • 49
  • 70