COIN-OR::LEMON - Graph Library

Changeset 209:765619b7cbb2 in lemon for lemon/time_measure.h


Ignore:
Timestamp:
07/13/08 20:51:02 (11 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

Apply unify-sources.sh to the source tree

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/time_measure.h

    r157 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    6565    double cstime;
    6666    double rtime;
    67  
    68     void _reset() { 
     67
     68    void _reset() {
    6969      utime = stime = cutime = cstime = rtime = 0;
    7070    }
     
    9797      FILETIME create, exit, kernel, user;
    9898      if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
    99         utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
    100         stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
    101         cutime = 0;
    102         cstime = 0;
     99        utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
     100        stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
     101        cutime = 0;
     102        cstime = 0;
    103103      } else {
    104         rtime = 0;
    105         utime = 0;
    106         stime = 0;
    107         cutime = 0;
    108         cstime = 0;
     104        rtime = 0;
     105        utime = 0;
     106        stime = 0;
     107        cutime = 0;
     108        cstime = 0;
    109109      }
    110 #endif     
    111     }
    112  
     110#endif
     111    }
     112
    113113    /// Constructor initializing with zero
    114114    TimeStamp()
     
    116116    ///Constructor initializing with the current time values of the process
    117117    TimeStamp(void *) { stamp();}
    118  
     118
    119119    ///Set every time value to zero
    120120    TimeStamp &reset() {_reset();return *this;}
     
    191191      return t-*this;
    192192    }
    193  
     193
    194194    friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
    195  
     195
    196196    ///Gives back the user time of the process
    197197    double userTime() const
     
    206206    ///Gives back the user time of the process' children
    207207
    208     ///\note On <tt>WIN32</tt> platform this value is not calculated. 
     208    ///\note On <tt>WIN32</tt> platform this value is not calculated.
    209209    ///
    210210    double cUserTime() const
     
    214214    ///Gives back the user time of the process' children
    215215
    216     ///\note On <tt>WIN32</tt> platform this value is not calculated. 
     216    ///\note On <tt>WIN32</tt> platform this value is not calculated.
    217217    ///
    218218    double cSystemTime() const
     
    224224  };
    225225
    226   TimeStamp operator*(double b,const TimeStamp &t) 
     226  TimeStamp operator*(double b,const TimeStamp &t)
    227227  {
    228228    return t*b;
    229229  }
    230  
     230
    231231  ///Prints the time counters
    232232
     
    300300    TimeStamp start_time; //This is the relativ start-time if the timer
    301301                          //is _running, the collected _running time otherwise.
    302    
     302
    303303    void _reset() {if(_running) start_time.stamp(); else start_time.reset();}
    304  
    305   public: 
     304
     305  public:
    306306    ///Constructor.
    307307
     
    332332
    333333    ///Start the time counters
    334    
     334
    335335    ///This function starts the time counters.
    336336    ///
     
    338338    ///until the same amount of \ref stop() is called.
    339339    ///\sa stop()
    340     void start() 
     340    void start()
    341341    {
    342342      if(_running) _running++;
    343343      else {
    344         _running=1;
    345         TimeStamp t;
    346         t.stamp();
    347         start_time=t-start_time;
     344        _running=1;
     345        TimeStamp t;
     346        t.stamp();
     347        start_time=t-start_time;
    348348      }
    349349    }
    350350
    351    
     351
    352352    ///Stop the time counters
    353353
     
    355355    ///once, then the same number of stop() execution is necessary the really
    356356    ///stop the timer.
    357     /// 
     357    ///
    358358    ///\sa halt()
    359359    ///\sa start()
     
    361361    ///\sa reset()
    362362
    363     void stop() 
     363    void stop()
    364364    {
    365365      if(_running && !--_running) {
    366         TimeStamp t;
    367         t.stamp();
    368         start_time=t-start_time;
     366        TimeStamp t;
     367        t.stamp();
     368        start_time=t-start_time;
    369369      }
    370370    }
     
    384384    ///\sa reset()
    385385
    386     void halt() 
     386    void halt()
    387387    {
    388388      if(_running) {
    389         _running=0;
    390         TimeStamp t;
    391         t.stamp();
    392         start_time=t-start_time;
     389        _running=0;
     390        TimeStamp t;
     391        t.stamp();
     392        start_time=t-start_time;
    393393      }
    394394    }
     
    403403    ///zero).
    404404    int running()  { return _running; }
    405    
    406    
     405
     406
    407407    ///Restart the time counters
    408408
     
    410410    ///a reset() and a start() calls.
    411411    ///
    412     void restart() 
     412    void restart()
    413413    {
    414414      reset();
    415415      start();
    416416    }
    417    
     417
    418418    ///@}
    419419
     
    434434    ///Gives back the ellapsed user time of the process' children
    435435
    436     ///\note On <tt>WIN32</tt> platform this value is not calculated. 
     436    ///\note On <tt>WIN32</tt> platform this value is not calculated.
    437437    ///
    438438    double cUserTime() const
     
    442442    ///Gives back the ellapsed user time of the process' children
    443443
    444     ///\note On <tt>WIN32</tt> platform this value is not calculated. 
     444    ///\note On <tt>WIN32</tt> platform this value is not calculated.
    445445    ///
    446446    double cSystemTime() const
     
    488488  ///\sa NoTimeReport
    489489  ///\todo There is no test case for this
    490   class TimeReport : public Timer 
     490  class TimeReport : public Timer
    491491  {
    492492    std::string _title;
     
    499499    ///\param run Sets whether the timer should start immediately.
    500500
    501     TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) 
     501    TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true)
    502502      : Timer(run), _title(title), _os(os){}
    503503    ///\e Prints the ellapsed time on destruction.
    504     ~TimeReport() 
     504    ~TimeReport()
    505505    {
    506506      _os << _title << *this << std::endl;
    507507    }
    508508  };
    509      
     509
    510510  ///'Do nothing' version of \ref TimeReport
    511511
     
    528528    void start() {}
    529529    void stop() {}
    530     void halt() {} 
     530    void halt() {}
    531531    int running() { return 0; }
    532532    void restart() {}
     
    537537    double realTime() const { return 0; }
    538538  };
    539      
     539
    540540  ///Tool to measure the running time more exactly.
    541  
     541
    542542  ///This function calls \c f several times and returns the average
    543543  ///running time. The number of the executions will be choosen in such a way
     
    551551  ///        total running time will be written into <tt>*full_time</tt>.
    552552  ///\return The average running time of \c f.
    553  
     553
    554554  template<class F>
    555555  TimeStamp runningTimeTest(F f,double min_time=10,unsigned int *num = NULL,
     
    567567    return full/total;
    568568  }
    569  
    570   /// @} 
     569
     570  /// @}
    571571
    572572
Note: See TracChangeset for help on using the changeset viewer.