【发布时间】:2017-06-24 06:33:40
【问题描述】:
我正在做一个项目,因为我需要检查两次之间的时差,以毫秒为单位获得时差,但现在我想要以微秒和纳秒为单位的时差来获得准确的时差
我的代码:
QDateTime oStartTime = QDateTime::currentDateTime();
// some operetions //the difference is in micro and nano seconds differ
QDateTime oEndTime = QDateTime::currentDateTime();
quint64 elapsed = oStartTime.daysTo(oEndTime)*1000*60*60*24 + oStartTime.time().msecsTo(oEndTime.time());
上面的代码只会给我毫秒的时间差异。我还需要微秒和纳秒。有什么建议如何获得微秒和纳秒的时间吗?
【问题讨论】:
-
std::chrono ,就是你在找的东西。 See here for example
-
chrono 不支持我使用 QT4.3.2 版本和 Visual Studio 2005 编译,所以可以得到微秒和纳秒
-
尝试 GetSystemTimeAsFileTime(LPFILETIME) ,其中 FILETIME 结构包含一个 64 位值,表示 100 纳秒时间戳的数量。