-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtime_and_clock.c
36 lines (25 loc) · 1.48 KB
/
time_and_clock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include<stdio.h>
#include<time.h>
//https://linux.die.net/man/3/clock_gettime
int main(int argc,char *argv[])
{
struct timespec tspec = {0, 0};
clock_getres(CLOCK_REALTIME, &tspec);
printf("\nResolution of CLOCK_REALTIME: %d seconds, %d nanoseconds\n", tspec.tv_sec, tspec.tv_nsec);
clock_gettime(CLOCK_REALTIME, &tspec);
printf("Clock real time: %d seconds, %d nanoseconds\n\n", tspec.tv_sec, tspec.tv_nsec);
clock_getres(CLOCK_MONOTONIC, &tspec);
printf("Resolution of CLOCK_MONOTONIC: %d seconds, %d nanoseconds\n", tspec.tv_sec, tspec.tv_nsec);
clock_gettime(CLOCK_MONOTONIC, &tspec);
printf("CLOCK_MONOTONIC (time since system start): %d seoncds, %d nanoseconds\n\n", tspec.tv_sec, tspec.tv_nsec);
clock_getres(CLOCK_PROCESS_CPUTIME_ID, &tspec);
printf("Resoltuon of CLOCK_PROCESS_CPUTIME_ID : %d seoncds, %d nanoseconds\n", tspec.tv_sec, tspec.tv_nsec);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tspec);
printf("CLOCK_PROCESS_CPUTIME_ID: %d seconds, %d nanoseconds\n\n", tspec.tv_sec, tspec.tv_nsec);
clock_getres(CLOCK_THREAD_CPUTIME_ID, &tspec);
printf("Resoltuon of CLOCK_THREAD_CPUTIME_ID: %d seoncds, %d nanoseconds\n", tspec.tv_sec, tspec.tv_nsec);
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tspec);
printf("CLOCK_THREAD_CPUTIME_ID: %d seconds, %d nanoseconds\n\n", tspec.tv_sec, tspec.tv_nsec);
printf("time(NULL): %d seconds\n", time(NULL));
return 0;
}