반응형
/***
struct timeval {
long tv_sec;
long tv_usec;
};
***/
#include <sys/time.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
struct timeval curr;
struct timeval prev;
struct timeval dur;
// prev_time
gettimeofday(&prev, NULL);
// processing
// current_time
gettimeofday(&curr, NULL);
// duration_time
dur.tv_sec = curr.tv_sec - prev.tv_sec;
dur.tv_usec = curr.tv_usec - prev.tv_usec;
if(dur.tv_usec < 0) {
dur.tv_usec += 1000000;
dur.tv_sec--;
}
}
반응형