윈도우의 경우 QueryPerformance QueryPerformanceCounter 라는 함수를 가지고
비교적 정확하게 측정할수있는데요(여러 프로그램을 돌리지 않는다고 가정할대..)
리눅스는 어떻게 측정해야 할지.. ??
#include <time.h> /* struct timespec { time_t tv_sec; // seconds long tv_nsec; // nanoseconds }; */ main() { struct timespec tp; int rs; rs = clock_gettime(CLOCK_REALTIME, &tp); printf("%ld %ld\n", tp.tv_sec, tp.tv_nsec); rs = clock_gettime(CLOCK_REALTIME, &tp); printf("%ld %ld\n", tp.tv_sec, tp.tv_nsec); return 0; }
$ gcc -o test test.c -lrt
[code:1]#include <time.h>/*
#include <time.h> /* struct timespec { time_t tv_sec; // seconds long tv_nsec; // nanoseconds }; */ main() { struct timespec tp; int rs; rs = clock_gettime(CLOCK_REALTIME, &tp); printf("%ld %ld\n", tp.tv_sec, tp.tv_nsec); rs = clock_gettime(CLOCK_REALTIME, &tp); printf("%ld %ld\n", tp.tv_sec, tp.tv_nsec); return 0; }$ gcc -o test test.c -lrt