Doc improvements
authoralpar
Tue, 06 Dec 2005 18:44:26 +0000
changeset 185178b5ea23f0f1
parent 1850 50d1d6acfcc2
child 1852 ffa7c6e96330
Doc improvements
lemon/counter.h
lemon/time_measure.h
     1.1 --- a/lemon/counter.h	Tue Dec 06 11:59:44 2005 +0000
     1.2 +++ b/lemon/counter.h	Tue Dec 06 18:44:26 2005 +0000
     1.3 @@ -95,6 +95,7 @@
     1.4    ///This class makes it easier to count certain events. You can increment
     1.5    ///or decrement the counter using operator++ and operator--.
     1.6    ///A report is automatically printed on destruction.
     1.7 +  ///\todo More doc
     1.8    class Counter 
     1.9    {
    1.10      std::string _title;
     2.1 --- a/lemon/time_measure.h	Tue Dec 06 11:59:44 2005 +0000
     2.2 +++ b/lemon/time_measure.h	Tue Dec 06 18:44:26 2005 +0000
     2.3 @@ -44,7 +44,8 @@
     2.4    /// TimeStamp's can be added to or substracted from each other and
     2.5    /// they can be pushed to a stream.
     2.6    ///
     2.7 -  /// In most cases, perhaps \ref Timer class is what you want to use instead.
     2.8 +  /// In most cases, perhaps the \ref Timer or the \ref TimeReport
     2.9 +  /// class is what you want to use instead.
    2.10    ///
    2.11    ///\author Alpar Juttner
    2.12  
    2.13 @@ -193,6 +194,30 @@
    2.14      return t*b;
    2.15    }
    2.16    
    2.17 +  ///Prints the time counters
    2.18 +
    2.19 +  ///Prints the time counters in the following form:
    2.20 +  ///
    2.21 +  /// <tt>u: XX.XXs s: XX.XXs cu: XX.XXs cs: XX.XXs real: XX.XXs</tt>
    2.22 +  ///
    2.23 +  /// where the values are the
    2.24 +  /// \li \c u: user cpu time,
    2.25 +  /// \li \c s: system cpu time,
    2.26 +  /// \li \c cu: user cpu time of children,
    2.27 +  /// \li \c cs: system cpu time of children,
    2.28 +  /// \li \c real: real time.
    2.29 +  /// \relates TimeStamp
    2.30 +  inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
    2.31 +  {
    2.32 +    long cls = sysconf(_SC_CLK_TCK);
    2.33 +    os << "u: " << double(t.getTms().tms_utime)/cls <<
    2.34 +      "s, s: " << double(t.getTms().tms_stime)/cls <<
    2.35 +      "s, cu: " << double(t.getTms().tms_cutime)/cls <<
    2.36 +      "s, cs: " << double(t.getTms().tms_cstime)/cls <<
    2.37 +      "s, real: " << t.realTime() << "s";
    2.38 +    return os;
    2.39 +  }
    2.40 +
    2.41    ///Class for measuring the cpu time and real time usage of the process
    2.42  
    2.43    ///Class for measuring the cpu time and real time usage of the process.
    2.44 @@ -229,12 +254,11 @@
    2.45    ///Also, if you start and stop the timer very frequently, it could lead
    2.46    ///distorted results.
    2.47    ///
    2.48 -  ///The \ref Timer also counts the number of \ref start()
    2.49 -  ///executions, and is stops only after the same amount (or more)
    2.50 -  ///\ref stop() "stop()"s. This can be useful e.g. to compute the running time
    2.51 -  ///of recursive functions.
    2.52 +  ///\note If you want to measure the running time of the execution of a certain
    2.53 +  ///function, consider the usage of \ref TimeReport instead.
    2.54    ///
    2.55    ///\todo This shouldn't be Unix (Linux) specific.
    2.56 +  ///\sa TimeReport
    2.57    ///
    2.58    ///\author Alpar Juttner
    2.59    class Timer
    2.60 @@ -252,16 +276,16 @@
    2.61      ///
    2.62      Timer(bool run=true) :_running(run) {_reset();}
    2.63  
    2.64 -    ///Computes the ellapsed time
    2.65 +    ///\name Control the state of the timer
    2.66 +    ///Basically a Timer can be either running or stopped,
    2.67 +    ///but it provides a bit finer control on the execution.
    2.68 +    ///The \ref Timer also counts the number of \ref start()
    2.69 +    ///executions, and is stops only after the same amount (or more)
    2.70 +    ///\ref stop() "stop()"s. This can be useful e.g. to compute the running time
    2.71 +    ///of recursive functions.
    2.72 +    ///
    2.73  
    2.74 -    ///This conversion computes the ellapsed time
    2.75 -    ///
    2.76 -    operator TimeStamp () const
    2.77 -    {
    2.78 -      TimeStamp t;
    2.79 -      t.stamp();
    2.80 -      return _running?t-start_time:start_time;
    2.81 -    }
    2.82 +    ///@{
    2.83  
    2.84      ///Reset and stop the time counters
    2.85  
    2.86 @@ -352,6 +376,12 @@
    2.87        start();
    2.88      }
    2.89      
    2.90 +    ///@}
    2.91 +
    2.92 +    ///\name Query Functions for the ellapsed time
    2.93 +
    2.94 +    ///@{
    2.95 +
    2.96      ///Gives back the ellapsed user time of the process
    2.97      double userTime() const
    2.98      {
    2.99 @@ -377,53 +407,87 @@
   2.100      {
   2.101        return operator TimeStamp().realTime();
   2.102      }
   2.103 +    ///Computes the ellapsed time
   2.104  
   2.105 +    ///This conversion computes the ellapsed time, therefore you can print
   2.106 +    ///the ellapsed time like this.
   2.107 +    ///\code
   2.108 +    ///  Timer T;
   2.109 +    ///  doSomething();
   2.110 +    ///  std::cout << T << '\n';
   2.111 +    ///\endcode
   2.112 +    operator TimeStamp () const
   2.113 +    {
   2.114 +      TimeStamp t;
   2.115 +      t.stamp();
   2.116 +      return _running?t-start_time:start_time;
   2.117 +    }
   2.118 +
   2.119 +
   2.120 +    ///@}
   2.121    };
   2.122  
   2.123    ///Same as \ref Timer but prints a report on destruction.
   2.124  
   2.125    ///Same as \ref Timer but prints a report on destruction.
   2.126 -  ///\todo Untested
   2.127 +  ///This example shows its usage.
   2.128 +  ///\code
   2.129 +  ///  void myAlg(ListGraph &g,int n)
   2.130 +  ///  {
   2.131 +  ///    TimeReport TR("Running time of myAlg: ");
   2.132 +  ///    ... //Here comes the algorithm
   2.133 +  ///  }
   2.134 +  ///\endcode
   2.135 +  ///
   2.136 +  ///\sa Timer
   2.137 +  ///\sa NoTimeReport
   2.138 +  ///\todo There is no test case for this
   2.139    class TimeReport : public Timer 
   2.140    {
   2.141      std::string _title;
   2.142      std::ostream &_os;
   2.143    public:
   2.144      ///\e
   2.145 -    
   2.146 -    TimeReport(std::string title,std::ostream &os,bool run) 
   2.147 +
   2.148 +    ///\param title This text will be printed before the ellapsed time.
   2.149 +    ///\param os The stream to print the report to.
   2.150 +    ///\param run Sets whether the timer should start immediately.
   2.151 +
   2.152 +    TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) 
   2.153        : Timer(run), _title(title), _os(os){}
   2.154 +    ///\e Prints the ellapsed time on destruction.
   2.155      ~TimeReport() 
   2.156      {
   2.157 -      _os << _title << this << std::endl;
   2.158 +      _os << _title << *this << std::endl;
   2.159      }
   2.160    };
   2.161        
   2.162 -  ///Prints the time counters
   2.163 +  ///'Do nothing' version of \ref TimeReport
   2.164  
   2.165 -  ///Prints the time counters in the following form:
   2.166 +  ///\sa TimeReport
   2.167    ///
   2.168 -  /// <tt>u: XX.XXs s: XX.XXs cu: XX.XXs cs: XX.XXs real: XX.XXs</tt>
   2.169 -  ///
   2.170 -  /// where the values are the
   2.171 -  /// \li \c u: user cpu time,
   2.172 -  /// \li \c s: system cpu time,
   2.173 -  /// \li \c cu: user cpu time of children,
   2.174 -  /// \li \c cs: system cpu time of children,
   2.175 -  /// \li \c real: real time.
   2.176 -  /// \relates TimeStamp
   2.177 -  inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
   2.178 +  class NoTimeReport
   2.179    {
   2.180 -    long cls = sysconf(_SC_CLK_TCK);
   2.181 -    os << "u: " << double(t.getTms().tms_utime)/cls <<
   2.182 -      "s, s: " << double(t.getTms().tms_stime)/cls <<
   2.183 -      "s, cu: " << double(t.getTms().tms_cutime)/cls <<
   2.184 -      "s, cs: " << double(t.getTms().tms_cstime)/cls <<
   2.185 -      "s, real: " << t.realTime() << "s";
   2.186 -    return os;
   2.187 -  }
   2.188 +  public:
   2.189 +    ///\e
   2.190 +    NoTimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) {}
   2.191 +    ///\e Do nothing.
   2.192 +    ~NoTimeReport() {}
   2.193  
   2.194 -  
   2.195 +    operator TimeStamp () const { return TimeStamp(); }
   2.196 +    void reset() {}
   2.197 +    void start() {}
   2.198 +    void stop() {}
   2.199 +    void halt() {} 
   2.200 +    int running() { return 0; }
   2.201 +    void restart() {}
   2.202 +    double userTime() const { return 0; }
   2.203 +    double systemTime() const { return 0; }
   2.204 +    double cUserTime() const { return 0; }
   2.205 +    double cSystemTime() const { return 0; }
   2.206 +    double realTime() const { return 0; }
   2.207 +  };
   2.208 +      
   2.209    ///Tool to measure the running time more exactly.
   2.210    
   2.211    ///This function calls \c f several times and returns the average