blob: c18daa51e93b39c07bed68b5a5e62f47c12d0c3a (
plain)
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
|
#include <math.h>
#include "time-stat.h"
static struct timespec start_time;
int start_timer(void)
{
int r;
r = clock_gettime(CLOCK_REALTIME, &start_time);
if (r == 0)
return 1;
else
return 0;
}
long int stop_timer(void)
{
struct timespec end_time;
int r;
double milliseconds = 0.0;
r = clock_gettime(CLOCK_REALTIME, &end_time);
if (r == 0) {
milliseconds = 1000.0 * (end_time.tv_sec - start_time.tv_sec) +
(end_time.tv_nsec - start_time.tv_nsec) / 1000000.0;
}
start_time.tv_sec = 0;
start_time.tv_nsec = 0;
return lround(milliseconds);
}
|