COIN-OR::LEMON - Graph Library

Changeset 1847:7cbc12e42482 in lemon-0.x for lemon


Ignore:
Timestamp:
12/05/05 18:03:31 (14 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2408
Message:
  • Changed and improved Timer interface
    • several new member functions
    • reset() -> restart() renaming
    • TimeReport?: a Timer that prints a report on destruction.
  • counter.h: a tool to measure the number of streps of algorithms.
  • New documentation module for time measuring and counting.
Location:
lemon
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • lemon/Makefile.am

    r1842 r1847  
    2828        bin_heap.h \
    2929        config.h \
     30        counter.h \
    3031        dijkstra.h \
    3132        dimacs.h \
  • lemon/simann.h

    r1633 r1847  
    55/// \file
    66/// \brief Simulated annealing framework.
     7///
     8/// \todo A test and some demo should be added
     9/// \todo Doc should be improved
    710/// \author Akos Ladanyi
    811
     
    299302          temp = 10000.0;
    300303          warmup = false;
    301           timer.reset();
     304          timer.restart();
    302305        }
    303306      }
  • lemon/time_measure.h

    r1839 r1847  
    1818#define LEMON_TIME_MEASURE_H
    1919
    20 ///\ingroup misc
     20///\ingroup timecount
    2121///\file
    2222///\brief Tools for measuring cpu usage
     
    3030namespace lemon {
    3131
    32   /// \addtogroup misc
     32  /// \addtogroup timecount
    3333  /// @{
    3434
     
    210210  ///  doSomething();
    211211  ///  std::cout << T << '\n';
    212   ///  T.reset();
     212  ///  T.restart();
    213213  ///  doSomethingElse();
    214214  ///  std::cout << T << '\n';
     
    224224  ///
    225225  ///\warning Depending on the operation system and its actual configuration
    226   ///the time counters have a certain (relatively big) granularity.
     226  ///the time counters have a certain (10ms on a typical Linux system)
     227  ///granularity.
    227228  ///Therefore this tool is not appropriate to measure very short times.
    228229  ///Also, if you start and stop the timer very frequently, it could lead
     
    239240  class Timer
    240241  {
    241     int running; //Timer is running iff running>0; (running>=0 always holds)
     242    int _running; //Timer is running iff _running>0; (_running>=0 always holds)
    242243    TimeStamp start_time; //This is the relativ start-time if the timer
    243                           //is running, the collected running time otherwise.
    244    
    245     void _reset() {if(running) start_time.stamp(); else start_time.reset();}
     244                          //is _running, the collected _running time otherwise.
     245   
     246    void _reset() {if(_running) start_time.stamp(); else start_time.reset();}
    246247 
    247248  public:
     
    250251    ///\param _running indicates whether or not the timer starts immediately.
    251252    ///
    252     Timer(bool _running=true) :running(_running) {_reset();}
     253    Timer(bool run=true) :_running(run) {_reset();}
    253254
    254255    ///Computes the ellapsed time
     
    260261      TimeStamp t;
    261262      t.stamp();
    262       return running?t-start_time:start_time;
    263     }
    264 
    265     ///Resets the time counters
    266 
    267     ///Resets the time counters
    268     ///
     263      return _running?t-start_time:start_time;
     264    }
     265
     266    ///Reset and stop the time counters
     267
     268    ///This function resets and stops the time counters
     269    ///\sa restart()
    269270    void reset()
    270271    {
     272      _running=0;
    271273      _reset();
    272274    }
     
    281283    void start()
    282284    {
    283       if(running) running++;
     285      if(_running) _running++;
    284286      else {
    285287        TimeStamp t;
     
    288290      }
    289291    }
     292
    290293   
    291294    ///Stop the time counters
    292295
    293     ///This function stops the time counters.
    294     ///
    295     ///\sa stop()
     296    ///This function stops the time counters. If start() was executed more than
     297    ///once, then the same number of stop() execution is necessary the really
     298    ///stop the timer.
     299    ///
     300    ///\sa halt()
     301    ///\sa start()
     302    ///\sa restart()
     303    ///\sa reset()
     304
    296305    void stop()
    297306    {
    298       if(running && !--running) {
     307      if(_running && !--_running) {
    299308        TimeStamp t;
    300309        t.stamp();
     
    302311      }
    303312    }
     313
     314    ///Halt (i.e stop immediately) the time counters
     315
     316    ///This function stops immediately the time counters.
     317    ///
     318    ///\sa stop()
     319    ///\sa restart()
     320    ///\sa reset()
     321
     322    void halt()
     323    {
     324      if(_running) {
     325        _running=0;
     326        TimeStamp t;
     327        t.stamp();
     328        start_time=t-start_time;
     329      }
     330    }
     331
     332    ///Returns the running state of the timer
     333
     334    ///This function returns the number of stop() exections that is
     335    ///necessary to really stop the timer.
     336    ///For example the timer
     337    ///is running if and only if the return value is \c true
     338    ///(i.e. greater than
     339    ///zero).
     340    int running()  { return _running; }
     341   
     342   
     343    ///Restart the time counters
     344
     345    ///This function is a shorthand for
     346    ///a reset() and a start() calls.
     347    ///
     348    void restart()
     349    {
     350      reset();
     351      start();
     352    }
    304353   
    305354    ///Gives back the ellapsed user time of the process
     
    331380  };
    332381
     382  ///Same as \ref Timer but prints a report on destruction.
     383
     384  ///Same as \ref Timer but prints a report on destruction.
     385  ///\todo Untested
     386  class TimeReport : public Timer
     387  {
     388    std::string _title;
     389    std::ostream &_os;
     390  public:
     391    ///\e
     392   
     393    TimeReport(std::string title,std::ostream &os,bool run)
     394      : Timer(run), _title(title), _os(os){}
     395    ~TimeReport()
     396    {
     397      _os << _title << this << std::endl;
     398    }
     399  };
     400     
    333401  ///Prints the time counters
    334402
Note: See TracChangeset for help on using the changeset viewer.