C ++跨平台高分辨率定时器 [英] C++ Cross-Platform High-Resolution Timer
问题描述
Boost.Timer 可能工作,但它取决于C函数 clock
和因此可能无法为您提供足够好的分辨率。
Boost.Date_Time包括 ptime
class 。请参阅 microsec_clock :: local_time
和 microsec_clock :: universal_time
上的文档,但请注意,Win32系统通常会不能通过此API实现微秒解析。
STLsoft 提供了其他功能, thin跨平台(Windows和Linux / Unix)围绕OS特定API的C ++包装器。其性能库有几个类,可以做你所需要的。 (要使其跨平台,请选择 winstl
和 performance_counter
> unixstl 命名空间,然后使用与您的平台匹配的命名空间。)
I'm looking to implement a simple timer mechanism in C++. The code should work in Windows and Linux. The resolution should be as precise as possible (at least millisecond accuracy). This will be used to simply track the passage of time, not to implement any kind of event-driven design. What is the best tool to accomplish this?
Boost.Timer might work, but it depends on the C function clock
and so may not have good enough resolution for you.
Boost.Date_Time includes a ptime
class that's been recommended on Stack Overflow before. See its docs on microsec_clock::local_time
and microsec_clock::universal_time
, but note its caveat that "Win32 systems often do not achieve microsecond resolution via this API."
STLsoft provides, among other things, thin cross-platform (Windows and Linux/Unix) C++ wrappers around OS-specific APIs. Its performance library has several classes that would do what you need. (To make it cross platform, pick a class like performance_counter
that exists in both the winstl
and unixstl
namespaces, then use whichever namespace matches your platform.)
这篇关于C ++跨平台高分辨率定时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!