COIN-OR::LEMON - Graph Library

Changeset 117:67253d52b284 in lemon-0.x


Ignore:
Timestamp:
02/22/04 16:17:58 (16 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@152
Message:

Timer class for measuring user/system time added.

Location:
src/work
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/work/alpar/f_ed_ka_demo.cc

    r108 r117  
    3232  int ret;
    3333  double pre_time=currTime();
     34  Timer ts;
     35 
    3436  ret = maxFlow(G,flow,cap,s,t);
    3537  double post_time=currTime();
     38  std::cout << "ellapsed time:" << ts << std::endl;
     39
    3640  //std::cout << "maximum flow: "<< std::endl;
    3741  //for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
  • src/work/marci/time_measure.h

    r73 r117  
    44
    55#include <sys/time.h>
     6#include <sys/times.h>
     7#include <fstream>
     8#include <iostream>
    69
    710double currTime() {
     
    1215}
    1316
     17class TimeStamp
     18{
     19  tms ts;
     20public:
     21
     22  tms &getTms() {return ts;}
     23  const tms &getTms() const {return ts;}
     24
     25  void stamp() {times(&ts);}
     26  TimeStamp() { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0;}
     27  TimeStamp(void *) { stamp();}
     28 
     29  TimeStamp &operator+=(const TimeStamp &b)
     30  {
     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;
     35    return *this;
     36  }
     37  TimeStamp operator+(const TimeStamp &b) const
     38  {
     39    TimeStamp t(*this);
     40    return t+=b;
     41  }
     42  TimeStamp &operator-=(const TimeStamp &b)
     43  {
     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;
     48    return *this;
     49  }
     50  TimeStamp operator-(const TimeStamp &b) const
     51  {
     52    TimeStamp t(*this);
     53    return t-=b;
     54  }
     55
     56  TimeStamp Ellapsed() const
     57  {
     58    TimeStamp t(NULL);
     59    return t-*this;
     60  }
     61 
     62  friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
     63 
     64};
     65
     66class Timer
     67{
     68  TimeStamp start_time;
     69
     70public:
     71  void reset() {start_time.stamp();}
     72  Timer() {reset();}
     73
     74  operator TimeStamp ()
     75  {
     76    TimeStamp t;
     77    t.stamp();
     78    return t-start_time;
     79  } 
     80};
     81
     82inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
     83{
     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 ]";
     89  return os;
     90}
     91
    1492#endif //TIME_MEASURE_H
Note: See TracChangeset for help on using the changeset viewer.