-
Notifications
You must be signed in to change notification settings - Fork 0
/
art_time.cpp
89 lines (70 loc) · 1.83 KB
/
art_time.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "art_time.h"
namespace Art
{
double ArtClock()
{
timespec cur_time;
clock_gettime(CLOCK_MONOTONIC, &cur_time);
long int mks = cur_time.tv_nsec / (long int) 1000;
long int s2mks = (long int) cur_time.tv_sec * 1000000 + mks;
double ss = (double) s2mks / 1000000.0;
// printf("s2mks = %ld mks = %ld s = %f\n", s2mks, mks, ss);
// printf("%lld.%.9ld", (long long)cur_time.tv_sec, cur_time.tv_nsec);
return ss;
}
Time::Time(){ updateTime(); }
Time::Time(const timespec& time_in){ time = time_in;}
Time::Time(long sec, long nsec)
{
time.tv_sec = sec;
time.tv_nsec = nsec;
}
/// Interfaces for getting the current time
void Time::now(timespec& cur_time)
{
clock_gettime(CLOCK_REALTIME, &cur_time);
}
double Time::now()
{
timespec cur_time;
now(cur_time);
return (double) cur_time.tv_sec + ( (double)cur_time.tv_nsec / (double)1000000000.0 );
}
/// Gets time and updates internal variables
void Time::updateTime()
{
now(time);
}
/// Full current time current time can be found as:
/// updateTime(); ///< Updates the internal variable
/// double cur_time = getMSec() + getMSec() + getNSec();
/// Time (s) with precision above 1000000 (s)
/// (doesn't update internal time by def)
double Time::getMSec( bool update )
{
return (double)( (long) time.tv_sec / (long) 1000000 )* (double) 1000000;
}
/// Time (s) reminder of division by 1000000 and rounded to nearest int
/// (doesn't update internal time by def)
double Time::getSec( bool update )
{
return (double)( (long) time.tv_sec % 1000000 );
}
/// nsec part of time converted to sec
double Time::getNSec( bool update )
{
return (double) time.tv_nsec / (double)1000000000.0;
}
Time& Time::operator+(double rhs)
{
}
Time& Time::operator-(double rhs)
{
}
Time& Time::operator+(const Art::Time& rhs)
{
}
Time& Time::operator-(const Art::Time& rhs)
{
}
}