C++ 시간 구하기 (gettimeofday, settimeofday)


#include <sys/time.h>

// ...

struct timeval start, end;
long mtime;

gettimeofday(&start, NULL);
while(1)
{
gettimeofday(&end, NULL);
mtime  = end.tv_sec  - start.tv_sec; // 경과 시간(초)

}
반복문 내에서 1초 주기로 실행해야 되는 구문이 있을 때 사용했다.
참고 : http://stackoverflow.com/questions/588307/c-obtaining-milliseconds-time-on-linux-clock-doesnt-seem-to-work-properl

댓글