COIN-OR::LEMON - Graph Library

Changeset 1847:7cbc12e42482 in lemon-0.x


Ignore:
Timestamp:
12/05/05 18:03:31 (18 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.
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • benchmark/bfs-bench.cc

    r1756 r1847  
    115115//        << dim*(1<<dim) << " edges):";
    116116
    117   T.reset();
     117  T.restart();
    118118  vector<Node> nodes;
    119119  addBiDirHyperCube(G,dim,nodes);
     
    121121  PrintTime("GENGRAPH",T);
    122122
    123   T.reset();
     123  T.restart();
    124124  {
    125125    for(int i=0;i<mul;i++)
     
    127127  }
    128128  PrintTime("BFS-STL",T);
    129   T.reset();
     129  T.restart();
    130130  {
    131131    for(int i=0;i<mul;i++)
     
    133133  }
    134134  PrintTime("BFS-OWN",T);
    135   T.reset();
     135  T.restart();
    136136  {
    137137    for(int i=0;i<mul;i++)
  • benchmark/graph-bench.cc

    r1756 r1847  
    4949 
    5050  PrintTime("BIG",T);
    51   T.reset();
     51  T.restart();
    5252  makeFullGraph<ListGraph>(nextPrim(100),nextPrim(30000),nextPrim(150));
    5353
  • benchmark/hcube.cc

    r1756 r1847  
    5353//        << dim*(1<<dim) << " edges):";
    5454
    55   T.reset();
     55  T.restart();
    5656  vector<Node> nodes;
    5757  addBiDirHyperCube(G,dim,nodes);
     
    5959  PrintTime("GENGRAPH",T);
    6060
    61   T.reset();
     61  T.restart();
    6262  Graph::EdgeMap<int> map(G);
    6363  for(int i=0;i<5;i++) {
     
    8585  PrintTime("GENLENGTHS",T);
    8686
    87   T.reset();
     87  T.restart();
    8888  {
    8989    Dijkstra<Graph> Dij(G,map);
     
    9393  PrintTime("DIJKSTRA",T);
    9494
    95   T.reset();
     95  T.restart();
    9696  {
    9797   Graph::EdgeMap<int> flow(G);
  • doc/groups.dox

    r1750 r1847  
    144144
    145145/**
     146@defgroup timecount Time measuring and Counting
     147@ingroup misc
     148Here you can find simple tools for measuring the performance
     149of algorithms.
     150*/
     151
     152/**
    146153@defgroup io_group Input Output
    147154Here you can find tools for imporing and exporting graphs and graph related
  • 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
  • test/Makefile.am

    r1833 r1847  
    1414        all_pairs_shortest_path_test \
    1515        bfs_test \
     16        counter_test \
    1617        dfs_test \
    1718        dijkstra_test \
     
    4950all_pairs_shortest_path_test_SOURCES = all_pairs_shortest_path_test.cc
    5051bfs_test_SOURCES = bfs_test.cc
     52counter_test_SOURCES = counter_test.cc
    5153dfs_test_SOURCES = dfs_test.cc
    5254dijkstra_test_SOURCES = dijkstra_test.cc
  • test/time_measure_test.cc

    r1689 r1847  
    3737  for(n=0;T.realTime()<1.0;n++) ;
    3838  std::cout << T << " (" << n << " time queries)\n";
    39   T.reset();
     39  T.restart();
    4040  while(T.realTime()<2.0) ;
    4141  std::cout << T << '\n';
Note: See TracChangeset for help on using the changeset viewer.