Get a timestamp in C in microseconds?

前端 未结 7 979
庸人自扰
庸人自扰 2020-12-01 01:43

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

相关标签:
7条回答
  • 2020-12-01 02:07

    use an unsigned long long (i.e. a 64 bit unit) to represent the system time:

    typedef unsigned long long u64;
    
    u64 u64useconds;
    struct timeval tv;
    
    gettimeofday(&tv,NULL);
    u64useconds = (1000000*tv.tv_sec) + tv.tv_usec;
    
    0 讨论(0)
提交回复
热议问题