如何以秒为单位测量插入时间?
我尝试使用:
struct timeval t1,t2;
我在插入输入之前检查了时间:
gettimeofday(&t1,NULL);
得到输入后也是一样的:
gettimeofday(&t2,NULL);
double elapsedTime=(t2.tv_sec - t1.tv_sec)*10000.0;
但它根本不准确!
我需要更好的方法来测量Inserting time中的秒数,并了解插入每个字符的秒数差异。
// trying to insert 5 chars
for(i=0; i<=4 ; i++)
{
gettimeofday(&t1,NULL); //get time before getting char
c=getchar();
gettimeofday(&t2,NULL); //get time after geting char
elapsedTime=(t1.tv_sec - t2.tv_sec)*10000.0;
printf("\n char number %d his elapsed time =%d\n",i,elapsedTime);
}
我需要知道秒率,插入“点击”字符作为输入,并以elapsedTime
秒为单位计算:
输出应该是这样的:
time between inserting first character and the second is : 0.002 seconds
time between..........second character and the third is: 1.008 seconds