---------------------------------------------------------------------------------------------------
以下是clock的代码
#include <stdio.h>
#include <time.h>
void main(void)
{
int i;
clock_t start, end, sum = 0;
printf("Clock test start!\n");
start = clock();
for(i=0;i<100000000;i++)
{
;
}
end = clock();
sum += end - start;
printf("Total time : %.9f secs .\n",(float)sum/CLOCKS_PER_SEC);
}
---------------------------------------------------------------------------------------------------
运行结果
[C66xx_0] Clock test start!
[C66xx_0] Total time : 4.500000477 secs .
用秒表计时,约为9秒左右。
---------------------------------------------------------------------------------------------------
time.h里的定义 :
#define CLOCKS_PER_SEC 200000000 /* 200 MHz */
---------------------------------------------------------------------------------------------------
问题:
1、请问clock()是通过什么机制来计时的?
2、我上面的程序是否正确,为什么运行结果与实际相差4秒左右呢?