Timer class for measuring user/system time added.
14 return double(tv.tv_sec)+double(tv.tv_usec)/1000000.0;
22 tms &getTms() {return ts;}
23 const tms &getTms() const {return ts;}
25 void stamp() {times(&ts);}
26 TimeStamp() { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0;}
27 TimeStamp(void *) { stamp();}
29 TimeStamp &operator+=(const TimeStamp &b)
31 ts.tms_utime+=b.ts.tms_utime;
32 ts.tms_stime+=b.ts.tms_stime;
33 ts.tms_cutime+=b.ts.tms_cutime;
34 ts.tms_cstime+=b.ts.tms_cstime;
37 TimeStamp operator+(const TimeStamp &b) const
42 TimeStamp &operator-=(const TimeStamp &b)
44 ts.tms_utime-=b.ts.tms_utime;
45 ts.tms_stime-=b.ts.tms_stime;
46 ts.tms_cutime-=b.ts.tms_cutime;
47 ts.tms_cstime-=b.ts.tms_cstime;
50 TimeStamp operator-(const TimeStamp &b) const
56 TimeStamp Ellapsed() const
62 friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
71 void reset() {start_time.stamp();}
82 inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
84 long cls = sysconf(_SC_CLK_TCK);
85 os << "[ u: " << double(t.getTms().tms_utime)/cls <<
86 "s, s: " << double(t.getTms().tms_stime)/cls <<
87 "s, cu: " << double(t.getTms().tms_cutime)/cls <<
88 "s, cs: " << double(t.getTms().tms_cstime)/cls << "s ]";
92 #endif //TIME_MEASURE_H