-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
30 lines (27 loc) · 823 Bytes
/
timer.h
File metadata and controls
30 lines (27 loc) · 823 Bytes
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
/* Example:
* #include "clock_timer.h"
* . . .
* double start, finish, elapsed;
* . . .
* GET_TIME(start);
* . . .
* Code to be timed
* . . .
* GET_TIME(finish);
* elapsed = finish - start;
* printf("The code to be timed took %e seconds\n", elapsed);
*/
#ifndef _CLOCK_TIMER_H
#define _CLOCK_TIMER_H
#include <sys/time.h>
#define BILLION 1000000000L
/* The argument now should be a double (not a pointer to a double) */
#define GET_TIME(now) { \
struct timespec time; \
clock_gettime(CLOCK_MONOTONIC_RAW, &time); \
now = time.tv_sec + time.tv_nsec/1000000000.0; \
}
#endif
//now = time.tv_sec + time.tv_nsec/1000000000.0; //seconds
//now = (BILLION * time.tv_sec) + time.tv_nsec; //nanoseconds
//clock_gettime(CLOCK_MONOTONIC_RAW, &time); //it is not affected by NTP