Created
May 21, 2011 03:26
-
-
Save laclefyoshi/984203 to your computer and use it in GitHub Desktop.
get nsec
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
/** | |
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