C++ mpi module for stochmagnet_main Package
CORE_Chrono.h
1 #ifndef CORE_Chrono_H
2 #define CORE_Chrono_H
3 
4 //inherits class header
5 #include "CORE_Object.h"
6 
7 
14 class CORE_Chrono : public CORE_Object {
15  // ATTRIBUTES
16 
17  public:
18 
19 
20 private:
21  // ASSOCIATION
22  //current time
23  tWallTime mStart;
24 
25  tUInt mYear;//in [1900, ...[
26  tCInt mMonth;//in [0,11]
27  tUCInt mDay;//day in [1,31]
28  tUCInt mWeekDay;//day in [0,6]
29  tUCInt mHour;//in [0,23]
30  tUCInt mMinute;//in [0,59]
31  tUCInt mSecond;//in [0,59]
32 
33  // METHODS
34 
35 
36 public:
37  // CONSTRUCTORS
41  tWallTime now=std::chrono::system_clock::now();
42  time_t tnow = std::chrono::system_clock::to_time_t(now);
43 
44  tm* ptm = localtime(&tnow);
45  mYear= ptm->tm_year + 1900;
46  mMonth = ptm->tm_mon ;
47  mDay= ptm->tm_mday;
48  mHour = ptm->tm_hour;
49  mMinute = ptm->tm_min;
50  mSecond= ptm->tm_sec;
51  mWeekDay=ptm->tm_wday;
52 
53 
54  }
55 
56 
57 
58 
59  // DESTRUCTORS
63  virtual ~CORE_Chrono(void) {
64  }
65 
66 
67 public:
68 
69 
70 private:
71 
72 
73 public:
74 
82  virtual tMemSize getMemorySize() const override{
83  return sizeof(*this)+getContentsMemorySize();
84  }
85 
86 public:
89  inline void start() {
90  mStart=std::chrono::high_resolution_clock::now();
91  }
95  inline tULLInt stop() {
96  tWallTime end=std::chrono::high_resolution_clock::now();
97  std::chrono::duration<tReal,std::milli> duration=(end-mStart);
98  mStart=end;
99  return (tULLInt) duration.count();
100  }
101 
105  inline static tULLInt GetClockTime() {
106  return std::clock();
107  }
112  inline static tULLInt GetClockDuration(const tULLInt& startTime) {
113  return (1000*(std::clock()-startTime))/CLOCKS_PER_SEC;
114  }
115 
126  inline static tULLInt ConvertDuration(tULLInt duration,
127  tUInt& d,
128  tUInt& h,
129  tUInt& m,
130  tUInt& s,
131  tUInt& ms) {
132 
133  tULLInt w=duration;
134 
135  //duration=ms+1000*(s+60*(m+60*(h+24*d)))
136  ms=duration%1000;
137  duration/=1000;
138  s=duration%60;
139  duration/=60;
140  m=duration%60;
141  duration/=60;
142  h=duration%24;
143  duration/=24;
144  d=duration;
145  return w;
146  }
150  inline static tString ConvertDurationToString(tULLInt duration) {
151 
152  tString ret;
153  ret.reserve(30);
154  //duration=ms+1000*(s+60*(m+60*(h+24*d)))
155  ret+=std::to_string((duration%1000))+"ms ";
156  duration/=1000;
157 
158  ret.insert(0,std::to_string((duration%60))+"s ");
159  duration/=60;
160 
161  ret.insert(0,std::to_string((duration%60))+"m ");
162  duration/=60;
163 
164  ret.insert(0,std::to_string((duration%24))+"h ");
165  duration/=24;
166 
167  ret.insert(0,std::to_string((duration))+"d ");
168  return ret;
169  }
170 
174  inline tString getDate() {
175  std::stringstream cstr;
176 
177  cstr<<mYear<<"/";
178  if (mMonth<9) cstr<<"0";
179  cstr<<((int)mMonth+1)<<"-";
180  if (mDay<10) cstr<<"0";
181  cstr<<((int)mDay);
182  cstr<<"/";
183  if (mHour<10) cstr<<"0";
184  cstr<<((int)mHour)<<":";
185  if (mMinute<10) cstr<<"0";
186  cstr<<((int)mMinute)<<":";
187  if (mSecond<10) cstr<<"0";
188  cstr<<((int)mSecond);
189  return cstr.str();
190  }
191 
194  inline static tString GetDate() {
195  CORE_Chrono time;
196  return time.getDate();
197  }
198 
199 private:
200 
201 
202 };
203 
204 #endif
this class describes the chono class by default write on standart output
Definition: CORE_Chrono.h:14
CORE_Chrono()
build a CORE_Chrono
Definition: CORE_Chrono.h:40
static tString ConvertDurationToString(tULLInt duration)
convert the duration the duration to string
Definition: CORE_Chrono.h:150
static tULLInt ConvertDuration(tULLInt duration, tUInt &d, tUInt &h, tUInt &m, tUInt &s, tUInt &ms)
convert the duration as days,hours,minutes,second,milliseconds,microseconds
Definition: CORE_Chrono.h:126
static tString GetDate()
return the current date as a string
Definition: CORE_Chrono.h:194
static tULLInt GetClockTime()
get the clock time
Definition: CORE_Chrono.h:105
tULLInt stop()
stop the chrono and return the duration time in micro seconds as an int
Definition: CORE_Chrono.h:95
tString getDate()
get the date in string
Definition: CORE_Chrono.h:174
void start()
start the chrono
Definition: CORE_Chrono.h:89
static tULLInt GetClockDuration(const tULLInt &startTime)
get the clock time duration
Definition: CORE_Chrono.h:112
virtual tMemSize getMemorySize() const override
return the memory size of the class and the memory size of all its attributes/associations
Definition: CORE_Chrono.h:82
virtual ~CORE_Chrono(void)
destroy a CORE_Chrono
Definition: CORE_Chrono.h:63
abstract base class for most classes.
Definition: CORE_Object.h:65
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278