[Lemon-commits] [lemon_svn] alpar: r153 - in hugo/trunk/src/work: alpar marci

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:37:50 CET 2006


Author: alpar
Date: Mon Feb 23 08:05:27 2004
New Revision: 153

Modified:
   hugo/trunk/src/work/alpar/f_ed_ka_demo.cc
   hugo/trunk/src/work/marci/time_measure.h

Log:
Improvements in 'Timer'/'TimeStamp'


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	Mon Feb 23 08:05:27 2004
@@ -23,26 +23,28 @@
 
   Graph G;
   NodeIt s, t;
+  Timer ts;
   Graph::DynEdgeMap<int> cap(G);
   readDimacsMaxFlow(std::cin, G, s, t, cap);
 
+  std::cout << "loading time: " << ts << std::endl;
+  ts.reset();
   std::cout << "edmonds karp demo..." << std::endl;
   Graph::DynEdgeMap<int> flow(G); //0 flow
   
   int ret;
-  double pre_time=currTime();
-  Timer ts;
+  //  double pre_time=currTime();
   
   ret = maxFlow(G,flow,cap,s,t);
-  double post_time=currTime();
-  std::cout << "ellapsed time:" << ts << std::endl;
+  //  double post_time=currTime();
+  std::cout << "running 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)<<") ";
   //}
   //std::cout<<std::endl;
-  std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
+  //  std::cout<<"elapsed time: " << post_time-pre_time << " sec"<< std::endl; 
   std::cout << "flow value: "<< ret << std::endl;
 
   return 0;

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	Mon Feb 23 08:05:27 2004
@@ -17,13 +17,23 @@
 class TimeStamp
 {
   tms ts;
+  double real_time;
+  
 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;}
+  double getRealTime() const {return real_time;}
+  void stamp()
+  {
+    timeval tv;
+    times(&ts);
+    gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6;
+  }
+  
+  TimeStamp()
+  { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;}
+  
   TimeStamp(void *) { stamp();}
   
   TimeStamp &operator+=(const TimeStamp &b)
@@ -32,6 +42,7 @@
     ts.tms_stime+=b.ts.tms_stime;
     ts.tms_cutime+=b.ts.tms_cutime;
     ts.tms_cstime+=b.ts.tms_cstime;
+    real_time+=b.real_time;
     return *this;
   }
   TimeStamp operator+(const TimeStamp &b) const
@@ -45,6 +56,7 @@
     ts.tms_stime-=b.ts.tms_stime;
     ts.tms_cutime-=b.ts.tms_cutime;
     ts.tms_cstime-=b.ts.tms_cstime;
+    real_time-=b.real_time;
     return *this;
   }
   TimeStamp operator-(const TimeStamp &b) const
@@ -61,6 +73,26 @@
   
   friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
   
+  double getUserTime() const
+  {
+    long cls = sysconf(_SC_CLK_TCK);
+    return double(ts.tms_utime)/cls;
+  }
+  double getSystemTime() const
+  {
+    long cls = sysconf(_SC_CLK_TCK);
+    return double(ts.tms_stime)/cls;
+  }
+  double getCUserTime() const
+  {
+    long cls = sysconf(_SC_CLK_TCK);
+    return double(ts.tms_cutime)/cls;
+  }
+  double getCSystemTime() const
+  {
+    long cls = sysconf(_SC_CLK_TCK);
+    return double(ts.tms_cstime)/cls;
+  }
 };
 
 class Timer
@@ -82,10 +114,11 @@
 inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
 {
   long cls = sysconf(_SC_CLK_TCK);
-  os << "[ u: " << double(t.getTms().tms_utime)/cls <<
+  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 ]";
+    "s, cs: " << double(t.getTms().tms_cstime)/cls <<
+    "s, real: " << t.getRealTime() << "s";
   return os;
 }
 



More information about the Lemon-commits mailing list