linux c clock函数持续时间一直为0;

#include "chat.h"
int main (void)
{
char ch;
long i = 10000000;
clock_t st,ed;
double duration;
st=clock();
while (1)
{
ch = getchar();
if(ch=='y')
break;
}
ed = clock();
duration = (double)(ed - st) / CLOCKS_PER_SEC;
printf( "%f seconds\n", duration );
return 0;

}

有没有更好的方法实现计时。。

可以试一下gettimeofday这个函数

linux c 中 int 调用 / 也是整除吧?

 duration = ((double)(ed - st)) / ((double)CLOCKS_PER_SEC);