MAIN.C :위해 clock_gettime
int sum()
{
int x = 100, y =200, z;
z =x;
z=y;
printf("value is %d", z);
return 1;
}
int main()
{
double starttime, stoptime;
int a=1, b=10, c;
starttime = GetTimeStamp(); // I am calculating time here.
printf("start time is %f", starttime);
c =a;
printf("value is %d", c);
c =b;
printf("value is %d", c);
c= a+b;
printf("value is %d", c);
printf("value is %d", c);
printf("value is %d", c);
printf("value is %d", c);
stoptime =GetTimeStamp(); // I want to know the time here.
printf("stop time is %f", stoptime);
return 0;
}
타이머 .c :
#define BILLION 1000000L
typedef unsigned int uint32_t;
int GetTimeStamp()
{
struct timespec start;
//double startTime;
// if((startTime = clock_gettime(CLOCK_REALTIME, &start)) == -1)
if((clock_gettime(CLOCK_REALTIME, &start)) == -1)
{
perror("clock gettime");
}
// startTime =start.tv_sec + 0.0000001 * start.tv_nsec; // to make it milli
return ((start.tv_sec + 0.0000001 * start.tv_nsec)/(double)BILLION);
}
timer.h :
#ifndef TIMESTAMP_H_
#define TIMESTAMP_H_
int GetTimeStamp();
#endif /* TIMESTAMP_H_ */
내가 무료 실행 타이머를 만들려하고 원하는 실행을 시작할 시간과 실행을 마치는 시간을 얻으십시오. 그래서 TIMER.c에서 위의 타이머를 만들었고 main.c에서 사용하고 있습니다. 나는 프로그램 구걸시 MAIN.c에서 GetTimeStamp()를 호출하고 있습니다. 출력 : 시작 시간과 종료 시간이 모두 같은 시간으로 표시됩니다. 1594.0000000
GetTimeStamp 함수의 반환 유형을 확인하고자 할 수 있습니다. 너에게 –