-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimemisc.cpp
More file actions
41 lines (34 loc) · 1.23 KB
/
timemisc.cpp
File metadata and controls
41 lines (34 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
#include "timemisc.h"
unsigned int timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y)
{
/* Perform the carry for the later subtraction by updating y. */
if (x->tv_usec < y->tv_usec) {
unsigned int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
y->tv_usec -= 1000000 * nsec;
y->tv_sec += nsec;
}
if (x->tv_usec - y->tv_usec > 1000000)
{
unsigned int nsec = (x->tv_usec - y->tv_usec) / 1000000;
y->tv_usec += 1000000 * nsec;
y->tv_sec -= nsec;
}
/* Compute the time remaining to wait.
tv_usec is certainly positive. */
result->tv_sec = x->tv_sec - y->tv_sec;
result->tv_usec = x->tv_usec - y->tv_usec;
/* Return 1 if result is negative. */
return x->tv_sec < y->tv_sec;
}
/**
* Print the time beetween the start and the end of the execution
*/
double get_time(struct timeval *start, struct timeval *end)
{
//struct timeval result;
double execution_time=0; // gets the execution time
struct timeval result;
timeval_subtract(&result, end, start);
execution_time = (result.tv_sec*1000000.0 + result.tv_usec)/1000000.0;
return execution_time;
}