OpenMS  2.4.0
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-2018.
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 #pragma once
36 
37 #include <OpenMS/config.h>
38 
39 #include <OpenMS/CONCEPT/Types.h>
41 
42 #ifdef OPENMS_HAS_SYS_TIME_H
43 #include <sys/time.h>
44 #endif
45 
46 #ifdef OPENMS_HAS_TIME_H
47 #include <ctime>
48 #endif
49 
50 namespace OpenMS
51 {
59  class OPENMS_DLLAPI StopWatch
60  {
61 public:
62 
66 
70  StopWatch();
71 
75  StopWatch(const StopWatch & stop_watch);
76 
80  virtual ~StopWatch();
81 
83 
86 
91  void clear();
92 
98  bool start();
99 
105  bool stop();
106 
111  void reset();
112 
114 
118 
122  double getClockTime() const;
123 
127  double getUserTime() const;
128 
132  double getSystemTime() const;
133 
138  double getCPUTime() const;
139 
141 
145 
151  StopWatch & operator=(const StopWatch & stop_watch);
152 
154 
158 
162  bool isRunning() const;
163 
171  bool operator==(const StopWatch & stop_watch) const;
172 
180  bool operator!=(const StopWatch & stop_watch) const;
181 
188  bool operator<(const StopWatch & stop_watch) const;
189 
196  bool operator<=(const StopWatch & stop_watch) const;
197 
204  bool operator>=(const StopWatch & stop_watch) const;
205 
212  bool operator>(const StopWatch & stop_watch) const;
213 
215 
223  String toString() const;
224 
228  static String toString(double time);
229 
230 private:
231 
232  static PointerSizeInt cpu_speed_;
233 
234 #ifdef OPENMS_WINDOWSPLATFORM
235  static PointerSizeInt clock_speed_;
236  typedef OPENMS_UINT64_TYPE TimeType; // do not use clock_t on Windows, since its not big enough for larger time intervals
237 #else
238  typedef clock_t TimeType;
239 #endif
240 
241  // state of stop watch, either true(on) or false(off)
243 
244  // clock seconds value when the stop watch was last started
245  PointerSizeInt start_secs_;
246 
247  // clock useconds value when the stop watch was last started
248  PointerSizeInt start_usecs_;
249 
250  // user time when the stop watch was last started
252 
253  // system time when the stop watch was last started
255 
256  // current accumulated clock seconds
257  PointerSizeInt current_secs_;
258 
259  // current accumulated clock useconds
260  PointerSizeInt current_usecs_;
261 
262  // current accumulated user time
264 
265  // current accumulated user time
267  };
268 
269 }
270 
271 
272 
A more convenient string class.
Definition: String.h:57
StopWatch Class.
Definition: StopWatch.h:59
PointerSizeInt current_usecs_
Definition: StopWatch.h:260
TimeType current_system_time_
Definition: StopWatch.h:266
TimeType current_user_time_
Definition: StopWatch.h:263
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
PointerSizeInt start_usecs_
Definition: StopWatch.h:248
TimeType start_system_time_
Definition: StopWatch.h:254
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
PointerSizeInt start_secs_
Definition: StopWatch.h:245
static PointerSizeInt cpu_speed_
Definition: StopWatch.h:232
bool is_running_
Definition: StopWatch.h:242
PointerSizeInt current_secs_
Definition: StopWatch.h:257
TimeType start_user_time_
Definition: StopWatch.h:251
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
String toString(T i)
toString functions (single argument)
Definition: StringUtils.h:68
clock_t TimeType
Definition: StopWatch.h:238