COIN-OR::LEMON - Graph Library

Ticket #442: c40a9d94442d.patch

File c40a9d94442d.patch, 4.2 KB (added by Alpar Juttner, 12 years ago)
  • lemon/base.cc

    # HG changeset patch
    # User Alpar Juttner <alpar@cs.elte.hu>
    # Date 1338890788 -7200
    # Node ID c40a9d94442d7143e733b38869ad98bf1f082b0a
    # Parent  38e1d4383262a146b119291383c65007f7704ec3
    New features in time_measure.h (#442)
    
    diff --git a/lemon/base.cc b/lemon/base.cc
    a b  
    2121
    2222#include<lemon/tolerance.h>
    2323#include<lemon/core.h>
     24#include<lemon/time_measure.h>
    2425namespace lemon {
    2526
    2627  float Tolerance<float>::def_epsilon = static_cast<float>(1e-4);
     
    3132  const Invalid INVALID = Invalid();
    3233#endif
    3334
     35  TimeStamp::Format TimeStamp::_format = TimeStamp::NORMAL;
     36
    3437} //namespace lemon
  • lemon/math.h

    diff --git a/lemon/math.h b/lemon/math.h
    a b  
    6565      return v!=v;
    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

    diff --git a/lemon/time_measure.h b/lemon/time_measure.h
    a b  
    3434#include <string>
    3535#include <fstream>
    3636#include <iostream>
     37#include <lemon/math.h>
    3738
    3839namespace lemon {
    3940
     
    6364    double cstime;
    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;
    6884    }
    6985
    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()
    74104    {
     
    224254  /// calculated.
    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  }
    234277
     
    468511  {
    469512    std::string _title;
    470513    std::ostream &_os;
     514    bool _active;
    471515  public:
    472516    ///Constructor
    473517
     
    475519    ///\param title This text will be printed before the ellapsed time.
    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;
     530      if(_active) _os << _title << *this << std::endl;
    484531    }
     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
    487545  ///'Do nothing' version of TimeReport