Skip to content

Instantly share code, notes, and snippets.

@iwagaki
Created January 27, 2015 09:42
Show Gist options
  • Save iwagaki/cda175a2dd77333e5ac5 to your computer and use it in GitHub Desktop.
Save iwagaki/cda175a2dd77333e5ac5 to your computer and use it in GitHub Desktop.
getimeofday v.s. clock_gettime
#include <cstdio>
#include <cstdlib>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
int main()
{
struct timeval now;
struct timezone zone;
struct timespec spec;
for (;;)
{
sleep(1);
gettimeofday(&now, &zone);
clock_gettime(CLOCK_MONOTONIC, &spec);
printf("gettimeofday: sec = %lu usec = %lu, clock_gettime: stv.tv_sec = %d setv.nsec = %d\n", (unsigned long)now.tv_sec, (unsigned long)now.tv_usec, (int)spec.tv_sec, (int)spec.tv_nsec);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment