C++ clock()函数主要是帮助我们实现计时的功能,clock_t是用来保存时间的数据类型,在time.h文件中
- #ifndef _CLOCK_T_DEFINED
- typedef long clock_t;
- #define _CLOCK_T_DEFINED
- #endif
CLOCKS_PER_SEC,它用来表示一秒钟会有多少个时钟计时单元,其定义如下:
- #define CLOCKS_PER_SEC ((clock_t)1000)
clock_t start,finish;
double duration;
start =clock();
。。。。
。。。。
。。。。
。。。。
finish = clock();
duration = (double)(finish-start)/CLOCKS_PER_SEC;