Under Windows there are some handy functions like QueryPerformanceCounter
from mmsystem.h
to create a high resolution timer.
Is there something similar for Linux?
相关问题
- 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
For Linux (and BSD) you want to use clock_gettime().
See: This answer for more information
For my money, there is no easier-to-use cross-platform timer than Qt's QTime class.
With C++11, use
std::chrono::high_resolution_clock
.Example:
Output:
It's been asked before here -- but basically, there is a boost ptime function you can use, or a POSIX clock_gettime() function which can serve basically the same purpose.
Here's a link describing how to do high-resolution timing on Linux and Windows... and no, Don't use RTSC.
https://web.archive.org/web/20160330004242/http://tdistler.com/2010/06/27/high-performance-timing-on-linux-windows
I have nothing but this link: http://www.mjmwired.net/kernel/Documentation/rtc.txt
I'm pretty sure RTC is what you are looking for though.
EDIT
Other answers seem more portable than mine.