Reputation: 4883
I am currently using clock()
function supplied by the time.h
library. It gives me time precision up to milliseconds. However, it's timing is based on CPU clock cycles. I need a function that instead of using CPU cycles as clock()
, will use system realtime with precision up to milliseconds.
I am using linux with gcc compiler.
Upvotes: 5
Views: 6842
Reputation: 37928
#include <sys/time.h>
...
timeval tv;
gettimeofday (&tv, NULL);
return double (tv.tv_sec) + 0.000001 * tv.tv_usec;
Upvotes: 8
Reputation: 1754
CLOCK_REALTIME
gives nanoseconds. Go no further, You might start a space-warp. :)
Upvotes: 0
Reputation: 72473
Linux (and POSIX.1-2001) provides gettimeofday()
to get current time to microsecond precision.
Upvotes: 3