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?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- How do you make an installer for your python progr
- Selecting only the first few characters in a strin
- Libgdx - Check if a key is being held down?
- What exactly do pointers store? (C++)
I have seen this implemented a few times as closed-source in-house solutions .... which all resorted to
#ifdef
solutions around native Windows hi-res timers on the one hand and Linux kernel timers usingstruct timeval
(seeman timeradd
) on the other hand.You can abstract this and a few Open Source projects have done it -- the last one I looked at was the CoinOR class CoinTimer but there are surely more of them.
SDL2 has an excellent cross-platform high-resolution timer. If however you need sub-millisecond accuracy, I wrote a very small cross-platform timer library here. It is compatible with both C++03 and C++11/higher versions of C++.