COIN-OR::LEMON - Graph Library

Changeset 1222:c40a9d94442d in lemon


Ignore:
Timestamp:
06/05/12 12:06:28 (13 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

New features in time_measure.h (#442)

Location:
lemon
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lemon/base.cc

    r554 r1222  
    2222#include<lemon/tolerance.h>
    2323#include<lemon/core.h>
     24#include<lemon/time_measure.h>
    2425namespace lemon {
    2526
     
    3233#endif
    3334
     35  TimeStamp::Format TimeStamp::_format = TimeStamp::NORMAL;
     36
    3437} //namespace lemon
  • lemon/math.h

    r956 r1222  
    6666    }
    6767
     68  ///Round a value to its closest integer
     69  inline double round(double r) {
     70    return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5);
     71  }
     72
    6873  /// @}
    6974
    7075} //namespace lemon
    7176
    72 #endif //LEMON_TOLERANCE_H
     77#endif //LEMON_MATH_H
  • lemon/time_measure.h

    r833 r1222  
    3535#include <fstream>
    3636#include <iostream>
     37#include <lemon/math.h>
    3738
    3839namespace lemon {
     
    6465    double rtime;
    6566
     67  public:
     68    ///Display format specifier
     69
     70    ///\e
     71    ///
     72    enum Format {
     73      /// Reports all measured values
     74      NORMAL = 0,
     75      /// Only real time and an error indicator is displayed
     76      SHORT = 1
     77    };
     78
     79  private:
     80    static Format _format;
     81
    6682    void _reset() {
    6783      utime = stime = cutime = cstime = rtime = 0;
     
    7086  public:
    7187
     88    ///Set output format
     89
     90    ///Set output format.
     91    ///
     92    ///The output format is global for all timestamp instances.
     93    static void format(Format f) { _format = f; }
     94    ///Retrieve the current output format
     95
     96    ///Retrieve the current output format
     97    ///
     98    ///The output format is global for all timestamp instances.
     99    static Format format() { return _format; }
     100
     101   
    72102    ///Read the current time values of the process
    73103    void stamp()
     
    225255  inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
    226256  {
    227     os << "u: " << t.userTime() <<
    228       "s, s: " << t.systemTime() <<
    229       "s, cu: " << t.cUserTime() <<
    230       "s, cs: " << t.cSystemTime() <<
    231       "s, real: " << t.realTime() << "s";
     257    switch(t._format)
     258      {
     259      case TimeStamp::NORMAL:
     260        os << "u: " << t.userTime() <<
     261          "s, s: " << t.systemTime() <<
     262          "s, cu: " << t.cUserTime() <<
     263          "s, cs: " << t.cSystemTime() <<
     264          "s, real: " << t.realTime() << "s";
     265        break;
     266      case TimeStamp::SHORT:
     267        double total = t.userTime()+t.systemTime()+
     268          t.cUserTime()+t.cSystemTime();
     269        os << t.realTime()
     270           << "s (err: " << round((t.realTime()-total)/
     271                                  t.realTime()*10000)/100
     272           << "%)";
     273        break;
     274      }
    232275    return os;
    233276  }
     
    469512    std::string _title;
    470513    std::ostream &_os;
     514    bool _active;
    471515  public:
    472516    ///Constructor
     
    476520    ///\param os The stream to print the report to.
    477521    ///\param run Sets whether the timer should start immediately.
    478     TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true)
    479       : Timer(run), _title(title), _os(os){}
     522    ///\param active Sets whether the report should actually be printed
     523    ///       on destruction.
     524    TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true,
     525               bool active=true)
     526      : Timer(run), _title(title), _os(os), _active(active) {}
    480527    ///Destructor that prints the ellapsed time
    481528    ~TimeReport()
    482529    {
    483       _os << _title << *this << std::endl;
    484     }
     530      if(_active) _os << _title << *this << std::endl;
     531    }
     532   
     533    ///Retrieve the activity status
     534
     535    ///\e
     536    ///
     537    bool active() const { return _active; }
     538    ///Set the activity status
     539
     540    /// This function set whether the time report should actually be printed
     541    /// on destruction.
     542    void active(bool a) { _active=a; }
    485543  };
    486544
Note: See TracChangeset for help on using the changeset viewer.