Last active
April 3, 2019 06:55
-
-
Save akx/a90631bdad05a2fb9d411d3a68ab6f99 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
static long long ts_usecs(struct timespec t) { | |
return (t.tv_sec * 1000000000 + t.tv_nsec); | |
} | |
int main() { | |
struct timespec t0, t1; | |
for (;;) { | |
clock_gettime(CLOCK_MONOTONIC, &t0); | |
clock_gettime(CLOCK_MONOTONIC, &t1); | |
long long us0 = ts_usecs(t0); | |
long long us1 = ts_usecs(t1); | |
long long delta = llabs(us0 - us1); | |
printf("%lld %lld %lld\n", us0, us1, delta); | |
} | |
} |
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
from time import clock_gettime, CLOCK_MONOTONIC | |
while True: | |
t0 = clock_gettime(CLOCK_MONOTONIC) * 1000000000 | |
t1 = clock_gettime(CLOCK_MONOTONIC) * 1000000000 | |
print('%d %d %d' % (t0, t1, abs(t1 - t0))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment