Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
StopWatch.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2013.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Chris Bielow $
32 // $Authors: Marc Sturm, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_SYSTEM_STOPWATCH_H
36 #define OPENMS_SYSTEM_STOPWATCH_H
37 
38 #include <OpenMS/config.h>
39 
40 #include <OpenMS/CONCEPT/Types.h>
42 
43 #ifdef OPENMS_HAS_SYS_TIME_H
44 #include <sys/time.h>
45 #endif
46 
47 #ifdef OPENMS_HAS_TIME_H
48 #include <ctime>
49 #endif
50 
51 #include <iostream>
52 
53 namespace OpenMS
54 {
62  class OPENMS_DLLAPI StopWatch
63  {
64 public:
65 
69 
73  StopWatch();
74 
78  StopWatch(const StopWatch & stop_watch);
79 
83  virtual ~StopWatch();
84 
86 
89 
94  void clear();
95 
101  bool start();
102 
108  bool stop();
109 
114  void reset();
115 
117 
121 
125  DoubleReal getClockTime() const;
126 
130  DoubleReal getUserTime() const;
131 
135  DoubleReal getSystemTime() const;
136 
141  inline DoubleReal getCPUTime() const
142  {
143  return getUserTime() + getSystemTime();
144  }
145 
147 
151 
157  StopWatch & operator=(const StopWatch & stop_watch);
158 
160 
164 
168  bool isRunning() const
169  {
170  return is_running_;
171  }
172 
180  bool operator==(const StopWatch & stop_watch) const;
181 
189  inline bool operator!=(const StopWatch & stop_watch) const
190  {
191  return !(*this == stop_watch);
192  }
193 
200  inline bool operator<(const StopWatch & stop_watch) const
201  {
202  return getCPUTime() < stop_watch.getCPUTime();
203  }
204 
211  inline bool operator<=(const StopWatch & stop_watch) const
212  {
213  return !(stop_watch < *this);
214  }
215 
222  inline bool operator>=(const StopWatch & stop_watch) const
223  {
224  return !(*this < stop_watch);
225  }
226 
233  inline bool operator>(const StopWatch & stop_watch) const
234  {
235  return stop_watch < *this;
236  }
237 
239 
243  static String toString(DoubleReal time);
244 
245 private:
246 
247  static PointerSizeInt cpu_speed_;
248 
249 #ifdef OPENMS_WINDOWSPLATFORM
250  static PointerSizeInt clock_speed_;
251  typedef OPENMS_UINT64_TYPE TimeType; // do not use clock_t on Windows, since its not big enough for larger time intervalls
252 #else
253  typedef clock_t TimeType;
254 #endif
255 
256  // state of stop watch, either true(on) or false(off)
258 
259  // clock seconds value when the stop watch was last started
260  PointerSizeInt start_secs_;
261 
262  // clock useconds value when the stop watch was last started
263  PointerSizeInt start_usecs_;
264 
265  // user time when the stop watch was last started
267 
268  // system time when the stop watch was last started
270 
271  // current accumulated clock seconds
272  PointerSizeInt current_secs_;
273 
274  // current accumulated clock useconds
275  PointerSizeInt current_usecs_;
276 
277  // current accumulated user time
279 
280  // current accumulated user time
282  };
283 
284 }
285 
286 #endif // OPENMS_SYSTEM_STOPWATCH_H
bool isRunning() const
Definition: StopWatch.h:168
A more convenient string class.
Definition: String.h:56
StopWatch Class.
Definition: StopWatch.h:62
bool operator>(const StopWatch &stop_watch) const
Definition: StopWatch.h:233
PointerSizeInt current_usecs_
Definition: StopWatch.h:275
TimeType current_system_time_
Definition: StopWatch.h:281
bool operator!=(const StopWatch &stop_watch) const
Definition: StopWatch.h:189
TimeType current_user_time_
Definition: StopWatch.h:278
PointerSizeInt start_usecs_
Definition: StopWatch.h:263
TimeType start_system_time_
Definition: StopWatch.h:269
PointerSizeInt start_secs_
Definition: StopWatch.h:260
static PointerSizeInt cpu_speed_
Definition: StopWatch.h:247
bool is_running_
Definition: StopWatch.h:257
DoubleReal getCPUTime() const
Definition: StopWatch.h:141
bool operator<=(const StopWatch &stop_watch) const
Definition: StopWatch.h:211
PointerSizeInt current_secs_
Definition: StopWatch.h:272
bool operator>=(const StopWatch &stop_watch) const
Definition: StopWatch.h:222
TimeType start_user_time_
Definition: StopWatch.h:266
bool operator<(const StopWatch &stop_watch) const
Definition: StopWatch.h:200
clock_t TimeType
Definition: StopWatch.h:253

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:21 using doxygen 1.8.5