【c++】计时函数

来源:互联网 发布:茶叶网络推广 编辑:程序博客网 时间:2024/04/30 10:16

C++ clock()函数主要是帮助我们实现计时的功能,clock_t是用来保存时间的数据类型,在time.h文件中

  1. #ifndef _CLOCK_T_DEFINED   
  2. typedef long clock_t;   
  3. #define _CLOCK_T_DEFINED   
  4. #endif  

CLOCKS_PER_SEC,它用来表示一秒钟会有多少个时钟计时单元,其定义如下:

  1. #define CLOCKS_PER_SEC ((clock_t)1000)
clock_t start,finish;double duration;     start =clock();  。。。。。。。。。。。。。。。。finish = clock(); duration = (double)(finish-start)/CLOCKS_PER_SEC;  


0 0