tags:

views:

8154

answers:

4

Hi!

Under Windows there are some handy functions like QueryPerformanceCounter from mmsystem.h to create a high resolution timer. Is there something similar for Linux?

A: 

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.

Oliver N.
A: 

gettimeofday() would be the best bet - see here: http://www.songho.ca/misc/timer/timer.html for details.

Andy Mikula
+5  A: 

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.

Nik Reiman
Didn't know that Boost provides timer functionality. Thank you :)
okoman
Or use the [HighResTimer](http://www.dre.vanderbilt.edu/Doxygen/Stable/ace/classACE__High__Res__Timer.html) from the [ACE](http://www.cs.wustl.edu/~schmidt/ACE.html) library.
lothar
+3  A: 

For Linux (and BSD) you want to use clock_gettime().

#include <sys/time.h>

int main()
{
   timespec ts;
   // clock_gettime(CLOCK_MONOTONIC, &ts); // Works on FreeBSD
   clock_gettime(CLOCK_REALTIME, &ts); // Works on Linux
}

See: This answer for more information

grieve
clock_gettime(CLOCK_MONOTONIC, works in Linux as well.
Maister