How do I get a microseconds timestamp in C?
I\'m trying to do:
struct timeval tv;
gettimeofday(&tv,NULL);
return tv.tv_usec;
Bu
You have two choices for getting a microsecond timestamp. The first (and best) choice, is to use the timeval type directly:
struct timeval GetTimeStamp() {
struct timeval tv;
gettimeofday(&tv,NULL);
return tv;
}
The second, and for me less desirable, choice is to build a uint64_t out of a timeval:
uint64_t GetTimeStamp() {
struct timeval tv;
gettimeofday(&tv,NULL);
return tv.tv_sec*(uint64_t)1000000+tv.tv_usec;
}