lemon/time_measure.h
changeset 209 765619b7cbb2
parent 157 2ccc1afc2c52
child 210 81cfc04531e8
     1.1 --- a/lemon/time_measure.h	Sun Jul 13 16:46:56 2008 +0100
     1.2 +++ b/lemon/time_measure.h	Sun Jul 13 19:51:02 2008 +0100
     1.3 @@ -1,6 +1,6 @@
     1.4 -/* -*- C++ -*-
     1.5 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
     1.6   *
     1.7 - * This file is a part of LEMON, a generic C++ optimization library
     1.8 + * This file is a part of LEMON, a generic C++ optimization library.
     1.9   *
    1.10   * Copyright (C) 2003-2008
    1.11   * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.12 @@ -64,8 +64,8 @@
    1.13      double cutime;
    1.14      double cstime;
    1.15      double rtime;
    1.16 -  
    1.17 -    void _reset() { 
    1.18 +
    1.19 +    void _reset() {
    1.20        utime = stime = cutime = cstime = rtime = 0;
    1.21      }
    1.22  
    1.23 @@ -96,26 +96,26 @@
    1.24  
    1.25        FILETIME create, exit, kernel, user;
    1.26        if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) {
    1.27 -	utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
    1.28 -	stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
    1.29 -	cutime = 0;
    1.30 -	cstime = 0;
    1.31 +        utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime;
    1.32 +        stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime;
    1.33 +        cutime = 0;
    1.34 +        cstime = 0;
    1.35        } else {
    1.36 -	rtime = 0;
    1.37 -	utime = 0;
    1.38 -	stime = 0;
    1.39 -	cutime = 0;
    1.40 -	cstime = 0;
    1.41 +        rtime = 0;
    1.42 +        utime = 0;
    1.43 +        stime = 0;
    1.44 +        cutime = 0;
    1.45 +        cstime = 0;
    1.46        }
    1.47 -#endif      
    1.48 +#endif
    1.49      }
    1.50 -  
    1.51 +
    1.52      /// Constructor initializing with zero
    1.53      TimeStamp()
    1.54      { _reset(); }
    1.55      ///Constructor initializing with the current time values of the process
    1.56      TimeStamp(void *) { stamp();}
    1.57 -  
    1.58 +
    1.59      ///Set every time value to zero
    1.60      TimeStamp &reset() {_reset();return *this;}
    1.61  
    1.62 @@ -190,9 +190,9 @@
    1.63        TimeStamp t(NULL);
    1.64        return t-*this;
    1.65      }
    1.66 -  
    1.67 +
    1.68      friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
    1.69 -  
    1.70 +
    1.71      ///Gives back the user time of the process
    1.72      double userTime() const
    1.73      {
    1.74 @@ -205,7 +205,7 @@
    1.75      }
    1.76      ///Gives back the user time of the process' children
    1.77  
    1.78 -    ///\note On <tt>WIN32</tt> platform this value is not calculated. 
    1.79 +    ///\note On <tt>WIN32</tt> platform this value is not calculated.
    1.80      ///
    1.81      double cUserTime() const
    1.82      {
    1.83 @@ -213,7 +213,7 @@
    1.84      }
    1.85      ///Gives back the user time of the process' children
    1.86  
    1.87 -    ///\note On <tt>WIN32</tt> platform this value is not calculated. 
    1.88 +    ///\note On <tt>WIN32</tt> platform this value is not calculated.
    1.89      ///
    1.90      double cSystemTime() const
    1.91      {
    1.92 @@ -223,11 +223,11 @@
    1.93      double realTime() const {return rtime;}
    1.94    };
    1.95  
    1.96 -  TimeStamp operator*(double b,const TimeStamp &t) 
    1.97 +  TimeStamp operator*(double b,const TimeStamp &t)
    1.98    {
    1.99      return t*b;
   1.100    }
   1.101 -  
   1.102 +
   1.103    ///Prints the time counters
   1.104  
   1.105    ///Prints the time counters in the following form:
   1.106 @@ -299,10 +299,10 @@
   1.107      int _running; //Timer is running iff _running>0; (_running>=0 always holds)
   1.108      TimeStamp start_time; //This is the relativ start-time if the timer
   1.109                            //is _running, the collected _running time otherwise.
   1.110 -    
   1.111 +
   1.112      void _reset() {if(_running) start_time.stamp(); else start_time.reset();}
   1.113 -  
   1.114 -  public: 
   1.115 +
   1.116 +  public:
   1.117      ///Constructor.
   1.118  
   1.119      ///\param run indicates whether or not the timer starts immediately.
   1.120 @@ -331,41 +331,41 @@
   1.121      }
   1.122  
   1.123      ///Start the time counters
   1.124 -    
   1.125 +
   1.126      ///This function starts the time counters.
   1.127      ///
   1.128      ///If the timer is started more than ones, it will remain running
   1.129      ///until the same amount of \ref stop() is called.
   1.130      ///\sa stop()
   1.131 -    void start() 
   1.132 +    void start()
   1.133      {
   1.134        if(_running) _running++;
   1.135        else {
   1.136 -	_running=1;
   1.137 -	TimeStamp t;
   1.138 -	t.stamp();
   1.139 -	start_time=t-start_time;
   1.140 +        _running=1;
   1.141 +        TimeStamp t;
   1.142 +        t.stamp();
   1.143 +        start_time=t-start_time;
   1.144        }
   1.145      }
   1.146  
   1.147 -    
   1.148 +
   1.149      ///Stop the time counters
   1.150  
   1.151      ///This function stops the time counters. If start() was executed more than
   1.152      ///once, then the same number of stop() execution is necessary the really
   1.153      ///stop the timer.
   1.154 -    /// 
   1.155 +    ///
   1.156      ///\sa halt()
   1.157      ///\sa start()
   1.158      ///\sa restart()
   1.159      ///\sa reset()
   1.160  
   1.161 -    void stop() 
   1.162 +    void stop()
   1.163      {
   1.164        if(_running && !--_running) {
   1.165 -	TimeStamp t;
   1.166 -	t.stamp();
   1.167 -	start_time=t-start_time;
   1.168 +        TimeStamp t;
   1.169 +        t.stamp();
   1.170 +        start_time=t-start_time;
   1.171        }
   1.172      }
   1.173  
   1.174 @@ -383,13 +383,13 @@
   1.175      ///\sa restart()
   1.176      ///\sa reset()
   1.177  
   1.178 -    void halt() 
   1.179 +    void halt()
   1.180      {
   1.181        if(_running) {
   1.182 -	_running=0;
   1.183 -	TimeStamp t;
   1.184 -	t.stamp();
   1.185 -	start_time=t-start_time;
   1.186 +        _running=0;
   1.187 +        TimeStamp t;
   1.188 +        t.stamp();
   1.189 +        start_time=t-start_time;
   1.190        }
   1.191      }
   1.192  
   1.193 @@ -402,19 +402,19 @@
   1.194      ///(i.e. greater than
   1.195      ///zero).
   1.196      int running()  { return _running; }
   1.197 -    
   1.198 -    
   1.199 +
   1.200 +
   1.201      ///Restart the time counters
   1.202  
   1.203      ///This function is a shorthand for
   1.204      ///a reset() and a start() calls.
   1.205      ///
   1.206 -    void restart() 
   1.207 +    void restart()
   1.208      {
   1.209        reset();
   1.210        start();
   1.211      }
   1.212 -    
   1.213 +
   1.214      ///@}
   1.215  
   1.216      ///\name Query Functions for the ellapsed time
   1.217 @@ -433,7 +433,7 @@
   1.218      }
   1.219      ///Gives back the ellapsed user time of the process' children
   1.220  
   1.221 -    ///\note On <tt>WIN32</tt> platform this value is not calculated. 
   1.222 +    ///\note On <tt>WIN32</tt> platform this value is not calculated.
   1.223      ///
   1.224      double cUserTime() const
   1.225      {
   1.226 @@ -441,7 +441,7 @@
   1.227      }
   1.228      ///Gives back the ellapsed user time of the process' children
   1.229  
   1.230 -    ///\note On <tt>WIN32</tt> platform this value is not calculated. 
   1.231 +    ///\note On <tt>WIN32</tt> platform this value is not calculated.
   1.232      ///
   1.233      double cSystemTime() const
   1.234      {
   1.235 @@ -487,7 +487,7 @@
   1.236    ///\sa Timer
   1.237    ///\sa NoTimeReport
   1.238    ///\todo There is no test case for this
   1.239 -  class TimeReport : public Timer 
   1.240 +  class TimeReport : public Timer
   1.241    {
   1.242      std::string _title;
   1.243      std::ostream &_os;
   1.244 @@ -498,15 +498,15 @@
   1.245      ///\param os The stream to print the report to.
   1.246      ///\param run Sets whether the timer should start immediately.
   1.247  
   1.248 -    TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) 
   1.249 +    TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true)
   1.250        : Timer(run), _title(title), _os(os){}
   1.251      ///\e Prints the ellapsed time on destruction.
   1.252 -    ~TimeReport() 
   1.253 +    ~TimeReport()
   1.254      {
   1.255        _os << _title << *this << std::endl;
   1.256      }
   1.257    };
   1.258 -      
   1.259 +
   1.260    ///'Do nothing' version of \ref TimeReport
   1.261  
   1.262    ///\sa TimeReport
   1.263 @@ -527,7 +527,7 @@
   1.264      void reset() {}
   1.265      void start() {}
   1.266      void stop() {}
   1.267 -    void halt() {} 
   1.268 +    void halt() {}
   1.269      int running() { return 0; }
   1.270      void restart() {}
   1.271      double userTime() const { return 0; }
   1.272 @@ -536,9 +536,9 @@
   1.273      double cSystemTime() const { return 0; }
   1.274      double realTime() const { return 0; }
   1.275    };
   1.276 -      
   1.277 +
   1.278    ///Tool to measure the running time more exactly.
   1.279 -  
   1.280 +
   1.281    ///This function calls \c f several times and returns the average
   1.282    ///running time. The number of the executions will be choosen in such a way
   1.283    ///that the full real running time will be roughly between \c min_time
   1.284 @@ -550,7 +550,7 @@
   1.285    ///\retval full_time if it is not \c NULL, then the actual
   1.286    ///        total running time will be written into <tt>*full_time</tt>.
   1.287    ///\return The average running time of \c f.
   1.288 -  
   1.289 +
   1.290    template<class F>
   1.291    TimeStamp runningTimeTest(F f,double min_time=10,unsigned int *num = NULL,
   1.292                              TimeStamp *full_time=NULL)
   1.293 @@ -566,8 +566,8 @@
   1.294      if(full_time) *full_time=full;
   1.295      return full/total;
   1.296    }
   1.297 -  
   1.298 -  /// @}  
   1.299 +
   1.300 +  /// @}
   1.301  
   1.302  
   1.303  } //namespace lemon