[Lemon-commits] [lemon_svn] alpar: r152 - in hugo/trunk/src/work: alpar marci
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:37:49 CET 2006
Author: alpar
Date: Sun Feb 22 16:17:58 2004
New Revision: 152
Modified:
hugo/trunk/src/work/alpar/f_ed_ka_demo.cc
hugo/trunk/src/work/marci/time_measure.h
Log:
Timer class for measuring user/system time added.
Modified: hugo/trunk/src/work/alpar/f_ed_ka_demo.cc
==============================================================================
--- hugo/trunk/src/work/alpar/f_ed_ka_demo.cc (original)
+++ hugo/trunk/src/work/alpar/f_ed_ka_demo.cc Sun Feb 22 16:17:58 2004
@@ -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<EachEdgeIt>(); e.valid(); ++e) {
// std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
Modified: hugo/trunk/src/work/marci/time_measure.h
==============================================================================
--- hugo/trunk/src/work/marci/time_measure.h (original)
+++ hugo/trunk/src/work/marci/time_measure.h Sun Feb 22 16:17:58 2004
@@ -3,6 +3,9 @@
#define TIME_MEASURE_H
#include <sys/time.h>
+#include <sys/times.h>
+#include <fstream>
+#include <iostream>
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
More information about the Lemon-commits
mailing list