2 #ifndef HUGO_TIME_MEASURE_H
3 #define HUGO_TIME_MEASURE_H
15 return double(tv.tv_sec)+double(tv.tv_usec)/1000000.0;
25 tms &getTms() {return ts;}
26 const tms &getTms() const {return ts;}
27 double getRealTime() const {return real_time;}
32 gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6;
36 { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;}
38 TimeStamp(void *) { stamp();}
40 TimeStamp &operator+=(const TimeStamp &b)
42 ts.tms_utime+=b.ts.tms_utime;
43 ts.tms_stime+=b.ts.tms_stime;
44 ts.tms_cutime+=b.ts.tms_cutime;
45 ts.tms_cstime+=b.ts.tms_cstime;
46 real_time+=b.real_time;
49 TimeStamp operator+(const TimeStamp &b) const
54 TimeStamp &operator-=(const TimeStamp &b)
56 ts.tms_utime-=b.ts.tms_utime;
57 ts.tms_stime-=b.ts.tms_stime;
58 ts.tms_cutime-=b.ts.tms_cutime;
59 ts.tms_cstime-=b.ts.tms_cstime;
60 real_time-=b.real_time;
63 TimeStamp operator-(const TimeStamp &b) const
69 TimeStamp Ellapsed() const
75 friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
77 double getUserTime() const
79 return double(ts.tms_utime)/sysconf(_SC_CLK_TCK);
81 double getSystemTime() const
83 return double(ts.tms_stime)/sysconf(_SC_CLK_TCK);
85 double getCUserTime() const
87 return double(ts.tms_cutime)/sysconf(_SC_CLK_TCK);
89 double getCSystemTime() const
91 return double(ts.tms_cstime)/sysconf(_SC_CLK_TCK);
99 void _reset() {start_time.stamp();}
104 operator TimeStamp ()
113 TimeStamp t(start_time);
119 inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
121 long cls = sysconf(_SC_CLK_TCK);
122 os << "u: " << double(t.getTms().tms_utime)/cls <<
123 "s, s: " << double(t.getTms().tms_stime)/cls <<
124 "s, cu: " << double(t.getTms().tms_cutime)/cls <<
125 "s, cs: " << double(t.getTms().tms_cstime)/cls <<
126 "s, real: " << t.getRealTime() << "s";
130 #endif //HUGO_TIME_MEASURE_H