Why is CLOCKS_PER_SEC not the actual number of clocks per second?

后端 未结 6 1588
情话喂你
情话喂你 2020-11-30 03:53

I have just written this short C++ program to approximate the actual number of clock ticks per second.

#include 
#include 

usi         


        
6条回答
  •  无人及你
    2020-11-30 04:48

    When you set int first_time = time(NULL);, time(NULL) might be "1 nanosecond away", (because it is truncated), from turning +1. Therefore, the: while(time(NULL) <= first_time) {} can be jumped over faster than 1 second, quicker than you expected.

    That's why there are less clocks in that "1 second" of yours.

提交回复
热议问题