# HG changeset patch # User alpar # Date 1077463078 0 # Node ID 67253d52b2845fb30f1cfc2355ea16b3a4e2f9d5 # Parent a987c6013ea073175bce3932cec09f0024488896 Timer class for measuring user/system time added. diff -r a987c6013ea0 -r 67253d52b284 src/work/alpar/f_ed_ka_demo.cc --- a/src/work/alpar/f_ed_ka_demo.cc Sun Feb 22 15:16:54 2004 +0000 +++ b/src/work/alpar/f_ed_ka_demo.cc Sun Feb 22 15:17:58 2004 +0000 @@ -31,8 +31,12 @@ int ret; double pre_time=currTime(); + Timer ts; + ret = maxFlow(G,flow,cap,s,t); double post_time=currTime(); + std::cout << "ellapsed time:" << ts << std::endl; + //std::cout << "maximum flow: "<< std::endl; //for(EachEdgeIt e=G.first(); e.valid(); ++e) { // std::cout<<"("<"< +#include +#include +#include double currTime() { timeval tv; @@ -11,4 +14,79 @@ return double(tv.tv_sec)+double(tv.tv_usec)/1000000.0; } +class TimeStamp +{ + tms ts; +public: + + tms &getTms() {return ts;} + const tms &getTms() const {return ts;} + + void stamp() {times(&ts);} + TimeStamp() { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0;} + TimeStamp(void *) { stamp();} + + TimeStamp &operator+=(const TimeStamp &b) + { + ts.tms_utime+=b.ts.tms_utime; + ts.tms_stime+=b.ts.tms_stime; + ts.tms_cutime+=b.ts.tms_cutime; + ts.tms_cstime+=b.ts.tms_cstime; + return *this; + } + TimeStamp operator+(const TimeStamp &b) const + { + TimeStamp t(*this); + return t+=b; + } + TimeStamp &operator-=(const TimeStamp &b) + { + ts.tms_utime-=b.ts.tms_utime; + ts.tms_stime-=b.ts.tms_stime; + ts.tms_cutime-=b.ts.tms_cutime; + ts.tms_cstime-=b.ts.tms_cstime; + return *this; + } + TimeStamp operator-(const TimeStamp &b) const + { + TimeStamp t(*this); + return t-=b; + } + + TimeStamp Ellapsed() const + { + TimeStamp t(NULL); + return t-*this; + } + + friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t); + +}; + +class Timer +{ + TimeStamp start_time; + +public: + void reset() {start_time.stamp();} + Timer() {reset();} + + operator TimeStamp () + { + TimeStamp t; + t.stamp(); + return t-start_time; + } +}; + +inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t) +{ + long cls = sysconf(_SC_CLK_TCK); + os << "[ u: " << double(t.getTms().tms_utime)/cls << + "s, s: " << double(t.getTms().tms_stime)/cls << + "s, cu: " << double(t.getTms().tms_cutime)/cls << + "s, cs: " << double(t.getTms().tms_cstime)/cls << "s ]"; + return os; +} + #endif //TIME_MEASURE_H