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

后端 未结 6 1579
情话喂你
情话喂你 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:23

    C99 standard

    The only thing the C99 N1256 standard draft says about CLOCKS_PER_SEC is that:

    CLOCKS_PER_SEC which expands to an expression with type clock_t (described below) that is the number per second of the value returned by the clock function

    As others mention, POSIX sets it to 1 million, which limits the precision of this to 1 microsecond. I think this is just a historical value from days where the maximum CPU frequencies were measured in Mega Hertz.

提交回复
热议问题