Scippy

SoPlex

Sequential object-oriented simPlex

timer.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file timer.h
17  * @brief Timer class.
18  */
19 
20 #ifndef _TIMER_H_
21 #define _TIMER_H_
22 
23 #include "soplex/spxdefines.h"
24 
25 namespace soplex
26 {
27 /**@class Timer
28  @ingroup Elementary
29 
30  @brief Wrapper for the system time query methods.
31 
32  In C or C++ programs, the usual way to measure time intervals,
33  e.g., running times of some complex computations, is to call one
34  of the provided system functions like %clock(), %time(), %times(),
35  %gettimeofday(), %getrusage() etc. By these functions one can
36  gather information about the process' user and system time and the
37  system clock (real time).
38 
39  Unfortunately, these functions are rather clumsy. The programmer
40  determines computation times by querying a (virtual) clock value
41  at the beginning and another one at the end of some computation
42  and converting the difference of these values into seconds. Some
43  functions impose restrictions; for instance, the values of
44  the ANSI C function %clock() are of high resolution but will wrap
45  around after about 36 minutes (cpu time). Most timing functions
46  take some data structure as argument that has to be allocated
47  before the call and from which the user has to pick up the
48  information of interest after the call. Problems can arise when
49  porting programs to other operating systems that do not support
50  standards like POSIX etc.
51 
52  In order to simplify measuring computation times and to hide the
53  system-dependencies involved, a concept of \em timers accounting the
54  process' system and real time is implemented. C and C++ interfaces
55  are provided as a set of functions operating on timers and a timer class
56  respectively.
57 
58  Look into the file timerfactory.h to see how to switch between different
59  timing types or to disable timing altogether.
60 
61  The idea is to provide a type Timer for objects that act like a stopwatch.
62  Operations on such an objects include: start accounting time, stop
63  accounting, read the actual time account and reset the objects time account
64  to zero.
65 
66  After initialization, accounting for the time can be
67  started by calling a function start(). Accounting is suspended by calling
68  a function stop() and can be resumed at any time by calling start()
69  again.
70 
71  For convenience, the actually accounted user time is returned by stop()
72  too. Function reset() re-initializes a timer clearing all time
73  accounts.
74 
75 */
76 class Timer
77 {
78 protected:
79 
80  //------------------------------------
81  /**@name Types */
82  ///@{
83  /// status of the timer
84  enum
85  {
86  RESET, ///< reset
87  STOPPED, ///< stopped
88  RUNNING ///< running
89  } status; ///< timer status
90 
91  ///@}
92 
93 public:
94 
95  //------------------------------------
96  /**@name Timers */
97  ///@{
98  /// types of timers
99  typedef enum
100  {
101  OFF = 0,
104  } TYPE;
105  ///@}
106 
107  //------------------------------------
108  /**@name Construction / destruction */
109  ///@{
110  /// default constructor
112  : status(RESET)
113  {}
114  /// copy constructor
115  Timer(const Timer& old)
116  : status(old.status)
117  {}
118  /// assignment operator
119  Timer& operator=(const Timer& old)
120  {
121  status = old.status;
122  return *this;
123  }
124  virtual ~Timer()
125  {}
126  ///@}
127 
128  //------------------------------------
129  /**@name Control */
130  ///@{
131  /// initialize timer, set timing accounts to zero.
132  virtual void reset() = 0;
133 
134  /// start timer, resume accounting user, system and real time.
135  virtual void start() = 0;
136 
137  /// stop timer, return accounted user time.
138  virtual Real stop() = 0;
139 
140  /// return type of timer
141  virtual TYPE type() = 0;
142  ///@}
143 
144  //------------------------------------
145  /**@name Access */
146  ///@{
147  /// return accounted time.
148  /// get accounted user, system, or real time when ticks were updated last
149  void getLastTimes(Real* userTime, Real* systemTime, Real* realTime) const;
150 
151 
152  virtual Real time() const = 0;
153 
154  /// return last accounted time without rechecking the clock
155  virtual Real lastTime() const = 0;
156 
157 
158  /// return accounted real time without rechecking the clock
159  Real realTimeLast() const;
160 
161  ///@}
162 };
163 } // namespace soplex
164 #endif // _TIMER_H_
virtual Real lastTime() const =0
return last accounted time without rechecking the clock
Timer()
default constructor
Definition: timer.h:111
virtual ~Timer()
Definition: timer.h:124
enum soplex::Timer::@2 status
status of the timer
virtual void start()=0
start timer, resume accounting user, system and real time.
virtual Real stop()=0
stop timer, return accounted user time.
double Real
Definition: spxdefines.h:256
Timer(const Timer &old)
copy constructor
Definition: timer.h:115
virtual Real time() const =0
Debugging, floating point type and parameter definitions.
Timer & operator=(const Timer &old)
assignment operator
Definition: timer.h:119
Everything should be within this namespace.
TYPE
types of timers
Definition: timer.h:99
void getLastTimes(Real *userTime, Real *systemTime, Real *realTime) const
return accounted time. get accounted user, system, or real time when ticks were updated last ...
Real realTimeLast() const
return accounted real time without rechecking the clock
virtual void reset()=0
initialize timer, set timing accounts to zero.
Wrapper for the system time query methods.
Definition: timer.h:76
virtual TYPE type()=0
return type of timer