COIN-OR::LEMON - Graph Library

Changeset 118:38e16c594a4f in lemon-0.x


Ignore:
Timestamp:
02/23/04 08:05:27 (20 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@153
Message:

Improvements in 'Timer'/'TimeStamp?'

Location:
src/work
Files:
2 edited

Legend:

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

    r117 r118  
    2424  Graph G;
    2525  NodeIt s, t;
     26  Timer ts;
    2627  Graph::DynEdgeMap<int> cap(G);
    2728  readDimacsMaxFlow(std::cin, G, s, t, cap);
    2829
     30  std::cout << "loading time: " << ts << std::endl;
     31  ts.reset();
    2932  std::cout << "edmonds karp demo..." << std::endl;
    3033  Graph::DynEdgeMap<int> flow(G); //0 flow
    3134 
    3235  int ret;
    33   double pre_time=currTime();
    34   Timer ts;
     36  //  double pre_time=currTime();
    3537 
    3638  ret = maxFlow(G,flow,cap,s,t);
    37   double post_time=currTime();
    38   std::cout << "ellapsed time:" << ts << std::endl;
     39  //  double post_time=currTime();
     40  std::cout << "running time: " << ts << std::endl;
    3941
    4042  //std::cout << "maximum flow: "<< std::endl;
     
    4345  //}
    4446  //std::cout<<std::endl;
    45   std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl;
     47  //  std::cout<<"elapsed time: " << post_time-pre_time << " sec"<< std::endl;
    4648  std::cout << "flow value: "<< ret << std::endl;
    4749
  • src/work/marci/time_measure.h

    r117 r118  
    1818{
    1919  tms ts;
     20  double real_time;
     21 
    2022public:
    2123
    2224  tms &getTms() {return ts;}
    2325  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;}
     26  double getRealTime() const {return real_time;}
     27  void stamp()
     28  {
     29    timeval tv;
     30    times(&ts);
     31    gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6;
     32  }
     33 
     34  TimeStamp()
     35  { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;}
     36 
    2737  TimeStamp(void *) { stamp();}
    2838 
     
    3343    ts.tms_cutime+=b.ts.tms_cutime;
    3444    ts.tms_cstime+=b.ts.tms_cstime;
     45    real_time+=b.real_time;
    3546    return *this;
    3647  }
     
    4657    ts.tms_cutime-=b.ts.tms_cutime;
    4758    ts.tms_cstime-=b.ts.tms_cstime;
     59    real_time-=b.real_time;
    4860    return *this;
    4961  }
     
    6274  friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
    6375 
     76  double getUserTime() const
     77  {
     78    long cls = sysconf(_SC_CLK_TCK);
     79    return double(ts.tms_utime)/cls;
     80  }
     81  double getSystemTime() const
     82  {
     83    long cls = sysconf(_SC_CLK_TCK);
     84    return double(ts.tms_stime)/cls;
     85  }
     86  double getCUserTime() const
     87  {
     88    long cls = sysconf(_SC_CLK_TCK);
     89    return double(ts.tms_cutime)/cls;
     90  }
     91  double getCSystemTime() const
     92  {
     93    long cls = sysconf(_SC_CLK_TCK);
     94    return double(ts.tms_cstime)/cls;
     95  }
    6496};
    6597
     
    83115{
    84116  long cls = sysconf(_SC_CLK_TCK);
    85   os << "[ u: " << double(t.getTms().tms_utime)/cls <<
     117  os << "u: " << double(t.getTms().tms_utime)/cls <<
    86118    "s, s: " << double(t.getTms().tms_stime)/cls <<
    87119    "s, cu: " << double(t.getTms().tms_cutime)/cls <<
    88     "s, cs: " << double(t.getTms().tms_cstime)/cls << "s ]";
     120    "s, cs: " << double(t.getTms().tms_cstime)/cls <<
     121    "s, real: " << t.getRealTime() << "s";
    89122  return os;
    90123}
Note: See TracChangeset for help on using the changeset viewer.