14 return double(tv.tv_sec)+double(tv.tv_usec)/1000000.0;
24 tms &getTms() {return ts;}
25 const tms &getTms() const {return ts;}
26 double getRealTime() const {return real_time;}
31 gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6;
35 { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;}
37 TimeStamp(void *) { stamp();}
39 TimeStamp &operator+=(const TimeStamp &b)
41 ts.tms_utime+=b.ts.tms_utime;
42 ts.tms_stime+=b.ts.tms_stime;
43 ts.tms_cutime+=b.ts.tms_cutime;
44 ts.tms_cstime+=b.ts.tms_cstime;
45 real_time+=b.real_time;
48 TimeStamp operator+(const TimeStamp &b) const
53 TimeStamp &operator-=(const TimeStamp &b)
55 ts.tms_utime-=b.ts.tms_utime;
56 ts.tms_stime-=b.ts.tms_stime;
57 ts.tms_cutime-=b.ts.tms_cutime;
58 ts.tms_cstime-=b.ts.tms_cstime;
59 real_time-=b.real_time;
62 TimeStamp operator-(const TimeStamp &b) const
68 TimeStamp Ellapsed() const
74 friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
76 double getUserTime() const
78 long cls = sysconf(_SC_CLK_TCK);
79 return double(ts.tms_utime)/cls;
81 double getSystemTime() const
83 long cls = sysconf(_SC_CLK_TCK);
84 return double(ts.tms_stime)/cls;
86 double getCUserTime() const
88 long cls = sysconf(_SC_CLK_TCK);
89 return double(ts.tms_cutime)/cls;
91 double getCSystemTime() const
93 long cls = sysconf(_SC_CLK_TCK);
94 return double(ts.tms_cstime)/cls;
100 TimeStamp start_time;
103 void reset() {start_time.stamp();}
106 operator TimeStamp ()
114 inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
116 long cls = sysconf(_SC_CLK_TCK);
117 os << "u: " << double(t.getTms().tms_utime)/cls <<
118 "s, s: " << double(t.getTms().tms_stime)/cls <<
119 "s, cu: " << double(t.getTms().tms_cutime)/cls <<
120 "s, cs: " << double(t.getTms().tms_cstime)/cls <<
121 "s, real: " << t.getRealTime() << "s";
125 #endif //TIME_MEASURE_H