'gettimeofday'에 해당되는 글 5건

  1. 2017.08.07 gettimeofday

gettimeofday

programming/C_C++ 2017.08.07 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 공간사랑

댓글을 달아 주세요