Skip to content

Instantly share code, notes, and snippets.

@zhangyangjing
Created April 28, 2018 14:31
Show Gist options
  • Save zhangyangjing/5ee32a99a5f44c7509a0c1b2fa5412bb to your computer and use it in GitHub Desktop.
Save zhangyangjing/5ee32a99a5f44c7509a0c1b2fa5412bb to your computer and use it in GitHub Desktop.
#include <time.h>
static long currentTimeInNs() {
struct timespec res;
clock_gettime(CLOCK_MONOTONIC, &res);
return (res.tv_sec * 1e9) + res.tv_nsec;
}
static long currentTimeInMs(void) {
struct timespec res;
clock_gettime(CLOCK_REALTIME, &res);
return 1000 * res.tv_sec + res.tv_nsec / 1e6;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment