This repository was archived by the owner on Jan 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtictac.c
More file actions
51 lines (44 loc) · 1.23 KB
/
tictac.c
File metadata and controls
51 lines (44 loc) · 1.23 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "tictac.h"
double get_time(int resolution)
/******************************************************************************
returns the time in the desired resolution
TIME_s - seconds
TIME_ms - miliseconds
TIME_us - microseconds
TIME_ns - nanoseconds
******************************************************************************/
{
struct timespec ts;
double ret;
clock_gettime(CLOCK_REALTIME, &ts);
switch (resolution)
{
case TIME_s:
ret = (((double)ts.tv_sec) + (((double)ts.tv_nsec) / 1000000000));
//printf("s %.20lf\n", ret);
return ret;
case TIME_ms:
ret = ((((double)ts.tv_sec) * 1000) + (((double)ts.tv_nsec) / 1000000));
//printf("ms %.20lf\n", ret);
return ret;
case TIME_us:
ret = ((((double)ts.tv_sec)) * 1000000 + (((double)ts.tv_nsec) / 1000));
//printf("us %.20lf\n", ret);
return ret;
case TIME_ns:
ret = ((((double)ts.tv_sec)) * 1000000000 + ((double)ts.tv_nsec));
//printf("ns %.20lf\n", ret);
return ret;
default:
fprintf(stderr, "treb_get_time() - resolution not supported\n");
exit(1);
}
}
void tic(double * time, int resolution)
{
*time = get_time(resolution);
}
void tac(double * time, int resolution)
{
*time = get_time(resolution) - *time;
}