clock_t
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <time.h> で定義
|
||
typedef /* unspecified */ clock_t; |
||
プロセスによって使用されたプロセッサ時間を表現可能な算術 (C11未満)実数 (C11以上)型。 処理系定義の範囲と精度を持ちます。
例
Run this code
#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
関連項目
| プログラム開始時から経過した生のプロセッサのクロック時刻を返します (関数) | |
| 1秒あたりのプロセッサクロックティック数 (マクロ定数) | |
clock_t の C++リファレンス
| |