Skip to content

Instantly share code, notes, and snippets.

@gfx
Created April 24, 2020 02:23
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 gfx/e726cb4b8f9185d2c839640d4008cc7a to your computer and use it in GitHub Desktop.
Save gfx/e726cb4b8f9185d2c839640d4008cc7a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
int main() {
printf("gettmeofday:\n");
for (int i = 0; i < 10; i++) {
struct timeval tv1, tv2;
gettimeofday(&tv1, NULL);
gettimeofday(&tv2, NULL);
printf("1. %lu %lu\n", (long)tv1.tv_sec, (long)tv1.tv_usec);
printf("2. %lu %lu\n", (long)tv2.tv_sec, (long)tv2.tv_usec);
}
printf("clock_gettime:\n");
for (int i = 0; i < 10; i++) {
struct timespec ts1, ts2;
clock_gettime(CLOCK_REALTIME, &ts1);
clock_gettime(CLOCK_REALTIME, &ts2);
printf("1. %lu %lu\n", (long)ts1.tv_sec, (long)ts1.tv_nsec);
printf("2. %lu %lu\n", (long)ts2.tv_sec, (long)ts2.tv_nsec);
}
return 0;
}
gettmeofday:
1. 1587695011 817334
2. 1587695011 817334
1. 1587695011 817348
2. 1587695011 817348
1. 1587695011 817355
2. 1587695011 817355
1. 1587695011 817361
2. 1587695011 817361
1. 1587695011 817366
2. 1587695011 817366
1. 1587695011 817372
2. 1587695011 817372
1. 1587695011 817379
2. 1587695011 817379
1. 1587695011 817385
2. 1587695011 817385
1. 1587695011 817391
2. 1587695011 817391
1. 1587695011 817397
2. 1587695011 817397
clock_gettime:
1. 1587695011 817406210
2. 1587695011 817406312
1. 1587695011 817412139
2. 1587695011 817412191
1. 1587695011 817417647
2. 1587695011 817417695
1. 1587695011 817423136
2. 1587695011 817423186
1. 1587695011 817428368
2. 1587695011 817428418
1. 1587695011 817434842
2. 1587695011 817434879
1. 1587695011 817440611
2. 1587695011 817440650
1. 1587695011 817445930
2. 1587695011 817445981
1. 1587695011 817451960
2. 1587695011 817452012
1. 1587695011 817458159
2. 1587695011 817458198
gettmeofday:
1. 1587694842 375851
2. 1587694842 375851
1. 1587694842 375857
2. 1587694842 375857
1. 1587694842 375859
2. 1587694842 375859
1. 1587694842 375860
2. 1587694842 375860
1. 1587694842 375862
2. 1587694842 375862
1. 1587694842 375864
2. 1587694842 375864
1. 1587694842 375866
2. 1587694842 375866
1. 1587694842 375867
2. 1587694842 375867
1. 1587694842 375869
2. 1587694842 375869
1. 1587694842 375871
2. 1587694842 375871
clock_gettime:
1. 1587694842 375877000
2. 1587694842 375877000
1. 1587694842 375879000
2. 1587694842 375879000
1. 1587694842 375881000
2. 1587694842 375881000
1. 1587694842 375882000
2. 1587694842 375882000
1. 1587694842 375884000
2. 1587694842 375884000
1. 1587694842 375886000
2. 1587694842 375886000
1. 1587694842 375888000
2. 1587694842 375888000
1. 1587694842 375890000
2. 1587694842 375890000
1. 1587694842 375891000
2. 1587694842 375891000
1. 1587694842 375893000
2. 1587694842 375893000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment