Skip to content

Instantly share code, notes, and snippets.

@akx
Last active April 3, 2019 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akx/a90631bdad05a2fb9d411d3a68ab6f99 to your computer and use it in GitHub Desktop.
Save akx/a90631bdad05a2fb9d411d3a68ab6f99 to your computer and use it in GitHub Desktop.
#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);
}
}
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