examples

Toy examples in single C files.
git clone git://henryandlizzy.uk/examples
Log | Files | Refs

clock-test.c (523B)


      1 #include <stdio.h>
      2 #include <unistd.h>
      3 #include <time.h>
      4 
      5 int main()
      6 {
      7 	struct timespec res, tp1, tp2;
      8 
      9 	clock_getres(CLOCK_MONOTONIC, &res);
     10 
     11 	clock_gettime(CLOCK_MONOTONIC, &tp1);
     12 	usleep(100);
     13 	clock_gettime(CLOCK_MONOTONIC, &tp2);
     14 
     15 	printf("resolution: %ld sec %ld ns\n", res.tv_sec, res.tv_nsec);
     16 	printf("time1: %ld / %ld\n", tp1.tv_sec, tp1.tv_nsec);
     17 	printf("time2: %ld / %ld\n", tp2.tv_sec, tp2.tv_nsec);
     18 	printf("diff: %ld ns\n", (tp2.tv_sec - tp1.tv_sec) * 1000000000 + tp2.tv_nsec - tp1.tv_nsec);
     19 
     20 	return 0;
     21 }