Skip to content

Instantly share code, notes, and snippets.

@laclefyoshi
Created May 21, 2011 03:26
Show Gist options
  • Save laclefyoshi/984203 to your computer and use it in GitHub Desktop.
Save laclefyoshi/984203 to your computer and use it in GitHub Desktop.
get nsec
/**
Copyright: (c) SAEKI Yoshiyasu
License : MIT-style license
<http://www.opensource.org/licenses/mit-license.php>
last updated: 2011/05/21
**/
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0
#include<time.h>
#else
#include<sys/time.h>
#endif
int main(int argc, char *argv[]) {
struct timespec ts;
#if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0
clock_gettime(CLOCK_REALTIME, &ts);
#else
struct timeval tv;
gettimeofday(&tv, NULL);
ts.tv_sec = tv.tv_sec;
ts.tv_nsec = tv.tv_usec * 1000;
#endif
printf("nsec: %u\n", (uint)ts.tv_nsec);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment