Skip to content

Instantly share code, notes, and snippets.

@aprell
Created June 15, 2012 17:43
Show Gist options
  • Save aprell/2937798 to your computer and use it in GitHub Desktop.
Save aprell/2937798 to your computer and use it in GitHub Desktop.
Simpler gettimeofday
#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