White Paper
Please understand my incorrect and poor korean expression
하드웨어 펄스측정또는 특정 연산의 시간측정등을 테스트 할수 있는 c source 입니다.
소스는 Linux Centos 4.4 [RedHat Linux] 에서 작성되었습니다.
많이들 복사해서 사용해보세요.
#include <stdio.h>
#include <sys/time.h>
#define BASETIME 100000L
void Settimer(void)
{
struct itimerval t;
t.it_interval.tv_sec = 0;
t.it_interval.tv_usec = 0;
t.it_value.tv_sec = BASETIME; /* 1시간 */
t.it_value.tv_usec = 0;
if (setitimer(ITIMER_REAL, &t, NULL) == -1){ perror("Failed to set virtual timer"); }
}
float Gettimer(void)
{
struct itimerval t;
float diftime;
if (getitimer(ITIMER_REAL, &t) == -1){perror("Failed to get virtual timer");}
diftime=(float)BASETIME-((float)(t.it_value.tv_sec)+((float)t.it_value.tv_usec/1000000.0));
return(diftime);
}
int main(int argc,char *argv[])
{
float d;
int i,j,k;
k=atoi(argv[1]);
Settimer(); // 시간측정시작
for(i=0;i<=10000;i++) // 이 루틴이 끝날때까지의 소요시간을 알아낸다.
{ // 즉 시간을 측정하고자 하는 루틴을 여기에 넣으면 된다.
for(j=0;j<=k;j++);
}
d=Gettimer(); // 위의 계산 소요 시간
printf(">%10.3f[sec]\n",d);
return 0;
}
위의 소스를 작설한 후 timer.c 로 저장합니다.
$gcc timer.c
$./a.out