【问题标题】:What is the unit of gettimeofday()?gettimeofday() 的单位是什么?
【发布时间】:2013-07-24 21:44:49
【问题描述】:

我有一个程序可以计算 pub-sub 模型中对象的延迟。我使用了以下函数作为时间戳:

uint64_t GetTimeStamp() {
    struct timeval tv;
    gettimeofday(&tv,NULL);
    return tv.tv_sec*(uint64_t)1000000+tv.tv_usec;
}

延迟以发布者和订阅者的时间戳差异来衡量。所以,我担心测量的延迟单位。是秒还是微秒??

【问题讨论】:

标签: c++ c gettimeofday


【解决方案1】:

timeval 结构有tv_sec,它为您提供秒的绝对值,以及tv_usec,它为您提供剩余微秒分数。

因此,您可以在微秒内获得分辨率。

欲了解更多信息,http://www.gnu.org/software/libc/manual/html_node/Elapsed-Time.html

【讨论】:

    【解决方案2】:

    tv.tv_sec 给出秒计数,tv.tv_usec 给出剩余的微秒计数。

    gettimeofday()原理及其准确性:

    How is the microsecond time of linux gettimeofday() obtained and what is its accuracy?

    Is gettimeofday() guaranteed to be of microsecond resolution?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-12
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 2013-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多