clock_t
定义于头文件 <time.h>
|
||
typedef /* unspecified */ clock_t; |
||
足以表示进程所用的处理器时间的算术 (C11 前)实数 (C11 起)类型。它拥有实现定义的范围和精度。
示例
运行此代码
#include <stdio.h> #include <time.h> volatile unsigned sink; int main (void) { clock_t start = clock(); for(size_t i=0; i<10000000; ++i) sink++; clock_t end = clock(); double cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("for loop took %f seconds to execute \n", cpu_time_used); }
可能的输出:
for loop took 0.033492 seconds to execute
引用
- C11 standard (ISO/IEC 9899:2011):
- 7.27.1/3 Components of time (p: 388)
- C99 standard (ISO/IEC 9899:1999):
- 7.23.1/3 Components of time (p: 338)
- C89/C90 standard (ISO/IEC 9899:1990):
- 4.12.1 Components of time
参阅
返回未加工的程序启动时开始经过的处理器时间 (函数) | |
处理器每秒的时间计数 (宏常量) |