'programming/C_C++'에 해당되는 글 279건

  1. 2017.08.07 gettimeofday

gettimeofday

programming/C_C++ 2017. 8. 7. 14:21
반응형

 

/***
       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--;
    }

}

반응형
Posted by 공간사랑
,