Created
June 15, 2012 17:43
-
-
Save aprell/2937798 to your computer and use it in GitHub Desktop.
Simpler gettimeofday
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef WTIME_H | |
#define WTIME_H | |
#include <sys/time.h> | |
#include <time.h> | |
// Seconds, milliseconds, or microseconds since the Epoch | |
static inline double wtime_sec(void) | |
{ | |
struct timeval tv; | |
gettimeofday(&tv, NULL); | |
return tv.tv_sec + tv.tv_usec / 1e6; | |
} | |
static inline double wtime_msec(void) | |
{ | |
struct timeval tv; | |
gettimeofday(&tv, NULL); | |
return tv.tv_sec * 1e3 + tv.tv_usec / 1e3; | |
} | |
static inline double wtime_usec(void) | |
{ | |
struct timeval tv; | |
gettimeofday(&tv, NULL); | |
return tv.tv_sec * 1e6 + tv.tv_usec; | |
} | |
#endif // WTIME_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment