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-2015.
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 namespace OpenMS
52 {
60  class OPENMS_DLLAPI StopWatch
61  {
62 public:
63 
67 
71  StopWatch();
72 
76  StopWatch(const StopWatch & stop_watch);
77 
81  virtual ~StopWatch();
82 
84 
87 
92  void clear();
93 
99  bool start();
100 
106  bool stop();
107 
112  void reset();
113 
115 
119 
123  double getClockTime() const;
124 
128  double getUserTime() const;
129 
133  double getSystemTime() const;
134 
139  inline double getCPUTime() const
140  {
141  return getUserTime() + getSystemTime();
142  }
143 
145 
149 
155  StopWatch & operator=(const StopWatch & stop_watch);
156 
158 
162 
166  bool isRunning() const
167  {
168  return is_running_;
169  }
170 
178  bool operator==(const StopWatch & stop_watch) const;
179 
187  inline bool operator!=(const StopWatch & stop_watch) const
188  {
189  return !(*this == stop_watch);
190  }
191 
198  inline bool operator<(const StopWatch & stop_watch) const
199  {
200  return getCPUTime() < stop_watch.getCPUTime();
201  }
202 
209  inline bool operator<=(const StopWatch & stop_watch) const
210  {
211  return !(stop_watch < *this);
212  }
213 
220  inline bool operator>=(const StopWatch & stop_watch) const
221  {
222  return !(*this < stop_watch);
223  }
224 
231  inline bool operator>(const StopWatch & stop_watch) const
232  {
233  return stop_watch < *this;
234  }
235 
237 
241  static String toString(double time);
242 
243 private:
244 
246 
247 #ifdef OPENMS_WINDOWSPLATFORM
248  static PointerSizeInt clock_speed_;
249  typedef OPENMS_UINT64_TYPE TimeType; // do not use clock_t on Windows, since its not big enough for larger time intervals
250 #else
251  typedef clock_t TimeType;
252 #endif
253 
254  // state of stop watch, either true(on) or false(off)
256 
257  // clock seconds value when the stop watch was last started
259 
260  // clock useconds value when the stop watch was last started
262 
263  // user time when the stop watch was last started
265 
266  // system time when the stop watch was last started
268 
269  // current accumulated clock seconds
271 
272  // current accumulated clock useconds
274 
275  // current accumulated user time
277 
278  // current accumulated user time
280  };
281 
282 }
283 
284 #endif // OPENMS_SYSTEM_STOPWATCH_H
bool isRunning() const
Definition: StopWatch.h:166
A more convenient string class.
Definition: String.h:57
StopWatch Class.
Definition: StopWatch.h:60
bool operator>(const StopWatch &stop_watch) const
Definition: StopWatch.h:231
#define OPENMS_UINT64_TYPE
Definition: config.h:103
PointerSizeInt current_usecs_
Definition: StopWatch.h:273
TimeType current_system_time_
Definition: StopWatch.h:279
bool operator!=(const StopWatch &stop_watch) const
Definition: StopWatch.h:187
TimeType current_user_time_
Definition: StopWatch.h:276
PointerSizeInt start_usecs_
Definition: StopWatch.h:261
TimeType start_system_time_
Definition: StopWatch.h:267
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
#define PointerSizeInt
Definition: config.h:107
PointerSizeInt start_secs_
Definition: StopWatch.h:258
static PointerSizeInt cpu_speed_
Definition: StopWatch.h:245
bool is_running_
Definition: StopWatch.h:255
bool operator<=(const StopWatch &stop_watch) const
Definition: StopWatch.h:209
PointerSizeInt current_secs_
Definition: StopWatch.h:270
bool operator>=(const StopWatch &stop_watch) const
Definition: StopWatch.h:220
TimeType start_user_time_
Definition: StopWatch.h:264
bool operator<(const StopWatch &stop_watch) const
Definition: StopWatch.h:198
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:68
clock_t TimeType
Definition: StopWatch.h:251
double getCPUTime() const
Definition: StopWatch.h:139

OpenMS / TOPP release 2.0.0 Documentation generated on Fri May 29 2015 17:20:30 using doxygen 1.8.9.1