1

I measured the cpu time spent by some code using:

 double start_clock = clock();
 // some code
 double end_clock = clock();
 total_clock = (end_clock-start_clock)/CLOCKS_PER_SEC;
 printf("%f",total_clock);

This prints out: 255.750000. What is this? My code took only 33 seconds (manually measured) to finish, so, where does 255 come from?

Idea: may it be because I have 8 threads running in parallel on a quadcore (which has 8 hardware thread)? 33*8 = 264 which is similar to 255.

HAL9000
  • 3,562
  • 3
  • 25
  • 47
  • Perhaps your value for CLOCKS_PER_SEC is wrong. Where is it defined? –  Jan 19 '14 at 22:25
  • 1
    If your compiler supports C++11, check out the [chrono](http://www.cplusplus.com/reference/chrono/). Also [duplicate]( http://stackoverflow.com/questions/2962785/c-using-clock-to-measure-time-in-multi-threaded-programs) – Gasim Jan 19 '14 at 22:26
  • 1
    @MikeW maybe in time.h – HAL9000 Jan 19 '14 at 22:26
  • I suggest to not use `clock` for high precision timing. Use either [chrono](http://www.cplusplus.com/reference/chrono/) or `gettimeofday` – Mihai Maruseac Jan 19 '14 at 22:52
  • see query performance counter on win and RDTSC on PC – Spektre Feb 11 '14 at 10:40

0 Answers0