COIN-OR::LEMON - Graph Library

Changeset 1689:f1795dafe42c in lemon-0.x


Ignore:
Timestamp:
09/28/05 10:14:39 (19 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2213
Message:
  • runningTimeTest(): a tool to measure running times more precisely.
  • TimeStamp? now uses double to count cpu-times
  • 'get's removed from the query functions of Times and TimeStamp?
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • benchmark/bench_tools.h

    r1435 r1689  
    8484{
    8585  lemon::TimeStamp S(T);
    86   std::cout << ID << ' ' << S.getUserTime() << ' '
    87             << S.getSystemTime() << ' ' << S.getRealTime() << std::endl;
     86  std::cout << ID << ' ' << S.userTime() << ' '
     87            << S.systemTime() << ' ' << S.realTime() << std::endl;
    8888}
    8989
     
    9292///
    9393template<class Graph>
    94 void addHiperCube(Graph &G,int dim,std::vector<typename Graph::Node> &nodes)
     94void addHyperCube(Graph &G,int dim,std::vector<typename Graph::Node> &nodes)
    9595{
    9696  GRAPH_TYPEDEF_FACTORY(Graph);
     
    108108///
    109109template<class Graph>
    110 void addBiDirHiperCube(Graph &G,int dim,std::vector<typename Graph::Node>&nodes)
     110void addBiDirHyperCube(Graph &G,int dim,std::vector<typename Graph::Node>&nodes)
    111111{
    112112  GRAPH_TYPEDEF_FACTORY(Graph);
  • benchmark/bfs-bench.cc

    r1632 r1689  
    118118  T.reset();
    119119  vector<Node> nodes;
    120   addBiDirHiperCube(G,dim,nodes);
     120  addBiDirHyperCube(G,dim,nodes);
    121121
    122122  PrintTime("GENGRAPH",T);
  • benchmark/hcube.cc

    r1632 r1689  
    5656  T.reset();
    5757  vector<Node> nodes;
    58   addBiDirHiperCube(G,dim,nodes);
     58  addBiDirHyperCube(G,dim,nodes);
    5959
    6060  PrintTime("GENGRAPH",T);
  • lemon/time_measure.h

    r1435 r1689  
    5151  class TimeStamp
    5252  {
    53     tms ts;
     53    struct rtms
     54    {
     55      double tms_utime;
     56      double tms_stime;
     57      double tms_cutime;
     58      double tms_cstime;
     59      rtms() {}
     60      rtms(tms ts) : tms_utime(ts.tms_utime), tms_stime(ts.tms_stime),
     61                     tms_cutime(ts.tms_cutime), tms_cstime(ts.tms_cstime) {}
     62    };
     63    rtms ts;
    5464    double real_time;
    5565 
     66    rtms &getTms() {return ts;}
     67    const rtms &getTms() const {return ts;}
     68
    5669  public:
    5770
    58     tms &getTms() {return ts;}
    59     const tms &getTms() const {return ts;}
    6071    ///Read the current time values of the process
    6172    void stamp()
    6273    {
    6374      timeval tv;
    64       times(&ts);
     75      tms _ts;
     76      times(&_ts);
    6577      gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6;
     78      ts=_ts;
    6679    }
    6780 
     
    104117      return t-=b;
    105118    }
     119    ///\e
     120
     121    ///\bug operator * and / gives rounded values!
     122    TimeStamp &operator*=(double b)
     123    {
     124      ts.tms_utime*=b;
     125      ts.tms_stime*=b;
     126      ts.tms_cutime*=b;
     127      ts.tms_cstime*=b;
     128      real_time*=b;
     129      return *this;
     130    }
     131    ///\e
     132    TimeStamp operator*(double b) const
     133    {
     134      TimeStamp t(*this);
     135      return t*=b;
     136    }
     137    friend TimeStamp operator*(double b,const TimeStamp &t);
     138    ///\e
     139    TimeStamp &operator/=(double b)
     140    {
     141      ts.tms_utime/=b;
     142      ts.tms_stime/=b;
     143      ts.tms_cutime/=b;
     144      ts.tms_cstime/=b;
     145      real_time/=b;
     146      return *this;
     147    }
     148    ///\e
     149    TimeStamp operator/(double b) const
     150    {
     151      TimeStamp t(*this);
     152      return t/=b;
     153    }
    106154    ///The time ellapsed since the last call of stamp()
    107155    TimeStamp ellapsed() const
     
    114162 
    115163    ///Gives back the user time of the process
    116     double getUserTime() const
     164    double userTime() const
    117165    {
    118166      return double(ts.tms_utime)/sysconf(_SC_CLK_TCK);
    119167    }
    120168    ///Gives back the system time of the process
    121     double getSystemTime() const
     169    double systemTime() const
    122170    {
    123171      return double(ts.tms_stime)/sysconf(_SC_CLK_TCK);
    124172    }
    125173    ///Gives back the user time of the process' children
    126     double getCUserTime() const
     174    double cUserTime() const
    127175    {
    128176      return double(ts.tms_cutime)/sysconf(_SC_CLK_TCK);
    129177    }
    130178    ///Gives back the user time of the process' children
    131     double getCSystemTime() const
     179    double cSystemTime() const
    132180    {
    133181      return double(ts.tms_cstime)/sysconf(_SC_CLK_TCK);
    134182    }
    135183    ///Gives back the real time of the process
    136     double getRealTime() const {return real_time;}
     184    double realTime() const {return real_time;}
    137185  };
    138186
     187  TimeStamp operator*(double b,const TimeStamp &t)
     188  {
     189    return t*b;
     190  }
     191 
    139192  ///Class measuring the cpu time and real time usage of the process
    140193
     
    198251
    199252    ///Gives back the ellapsed user time of the process
    200     double getUserTime() const
    201     {
    202       return operator TimeStamp().getUserTime();
     253    double userTime() const
     254    {
     255      return operator TimeStamp().userTime();
    203256    }
    204257    ///Gives back the ellapsed system time of the process
    205     double getSystemTime() const
    206     {
    207       return operator TimeStamp().getSystemTime();
     258    double systemTime() const
     259    {
     260      return operator TimeStamp().systemTime();
    208261    }
    209262    ///Gives back the ellapsed user time of the process' children
    210     double getCUserTime() const
    211     {
    212       return operator TimeStamp().getCUserTime();
     263    double cUserTime() const
     264    {
     265      return operator TimeStamp().cUserTime();
    213266    }
    214267    ///Gives back the ellapsed user time of the process' children
    215     double getCSystemTime() const
    216     {
    217       return operator TimeStamp().getCSystemTime();
     268    double cSystemTime() const
     269    {
     270      return operator TimeStamp().cSystemTime();
    218271    }
    219272    ///Gives back the ellapsed real time of the process
    220     double getRealTime() const
    221     {
    222       return operator TimeStamp().getRealTime();
     273    double realTime() const
     274    {
     275      return operator TimeStamp().realTime();
    223276    }
    224277
     
    245298      "s, cu: " << double(t.getTms().tms_cutime)/cls <<
    246299      "s, cs: " << double(t.getTms().tms_cstime)/cls <<
    247       "s, real: " << t.getRealTime() << "s";
     300      "s, real: " << t.realTime() << "s";
    248301    return os;
    249302  }
    250303
     304 
     305  ///Tool to measure the running time more exactly.
     306 
     307  ///This function calls \c f several times and returns the average
     308  ///running time. The number of the executions will be choosen in such a way
     309  ///that the full running time will be roughly between \c min_time
     310  ///and <tt>2*min_time</tt>.
     311  ///\param f the function object to be measured.
     312  ///\param min_time the minimum total running time.
     313  ///\retval num if it is not \c NULL, then *num will contain the actual
     314  ///        number of execution of \c f.
     315  ///\retval full_time if it is not \c NULL, then *full_time
     316  ///        will contain the actual
     317  ///        total running time.
     318  ///\return The average running time of \c f.
     319 
     320  template<class F>
     321  TimeStamp runningTimeTest(F &f,double min_time=10,int *num = NULL,
     322                        TimeStamp *full_time=NULL)
     323  {
     324    Timer t;
     325    TimeStamp full;
     326    int total=0;
     327    for(int tn=1;tn < 1<<24; tn*=2) {
     328      for(;total<tn;total++) f();
     329      full=t;
     330      if(full.realTime()>min_time) {
     331        if(num) *num=total;
     332        if(full_time) *full_time=full;
     333      return full/total;
     334      }
     335    }
     336    return TimeStamp();
     337  }
     338 
    251339  /// @} 
    252340
     341
    253342} //namespace lemon
    254343
  • test/time_measure_test.cc

    r1435 r1689  
    2424using namespace lemon;
    2525
     26void f()
     27{
     28  double d=0;
     29  for(int i=0;i<10000;i++)
     30    d+=0.1;
     31}
     32
    2633int main()
    2734{
    2835  Timer T;
    29   while(T.getRealTime()<1.0) ;
     36  int n;
     37  for(n=0;T.realTime()<1.0;n++) ;
     38  std::cout << T << " (" << n << " time queries)\n";
     39  T.reset();
     40  while(T.realTime()<2.0) ;
    3041  std::cout << T << '\n';
    31   T.reset();
    32   while(T.getRealTime()<2.0) ;
    33   std::cout << T << '\n';
     42  TimeStamp full;
     43  TimeStamp t=runningTimeTest(f,1,&n,&full);
     44  std::cout << t << " (" << n << " tests)\n";
     45  std::cout << "Total: " << full << "\n";
    3446 
    3547  return 0;
Note: See TracChangeset for help on using the changeset viewer.