挿入時間を秒単位で測定する方法は?
私は使用しようとしました:
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