| OpenMS 2.5.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-2020.
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>
40 #include <OpenMS/DATASTRUCTURES/String.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
102 bool start();
103
109 bool stop();
110
115 void reset();
116
118
122
126 double getClockTime() const;
127
131 double getUserTime() const;
132
136 double getSystemTime() const;
137
142 double getCPUTime() const;
143
145
149
155 StopWatch & operator=(const StopWatch & stop_watch);
156
158
162
166 bool isRunning() const;
167
175 bool operator==(const StopWatch & stop_watch) const;
176
184 bool operator!=(const StopWatch & stop_watch) const;
185
192 bool operator<(const StopWatch & stop_watch) const;
193
200 bool operator<=(const StopWatch & stop_watch) const;
201
208 bool operator>=(const StopWatch & stop_watch) const;
209
216 bool operator>(const StopWatch & stop_watch) const;
217
219
227 String toString() const;
228
232 static String toString(const double time);
233
234 private:
235
236 static PointerSizeInt cpu_speed_;
237
238 #ifdef OPENMS_WINDOWSPLATFORM
239 static PointerSizeInt clock_speed_;
240 typedef OPENMS_UINT64_TYPE TimeType; // do not use clock_t on Windows, since its not big enough for larger time intervals
241 #else
242 typedef clock_t TimeType;
243 #endif
244
245 // state of stop watch, either true(on) or false(off)
246 bool is_running_;
247
248 // clock seconds value when the stop watch was last started
249 PointerSizeInt start_secs_;
250
251 // clock useconds value when the stop watch was last started
252 PointerSizeInt start_usecs_;
253
254 // user time when the stop watch was last started
255 TimeType start_user_time_;
256
257 // system time when the stop watch was last started
258 TimeType start_system_time_;
259
260 // current accumulated clock seconds
261 PointerSizeInt current_secs_;
262
263 // current accumulated clock useconds
264 PointerSizeInt current_usecs_;
265
266 // current accumulated user time
267 TimeType current_user_time_;
268
269 // current accumulated user time
270 TimeType current_system_time_;
271 };
272
273 }
274
275
276
OpenMS::StopWatch::start_secs_
PointerSizeInt start_secs_
Definition: StopWatch.h:249
OpenMS::StopWatch::start_system_time_
TimeType start_system_time_
Definition: StopWatch.h:258
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::operator<
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
OpenMS::StringConversions::toString
String toString(const T &i)
fallback template for general purpose using Boost::Karma; more specializations below ...
Definition: StringUtils.h:85
KDTree::operator!=
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
OpenMS::StopWatch::current_secs_
PointerSizeInt current_secs_
Definition: StopWatch.h:261
Types.h
OpenMS::StopWatch::TimeType
clock_t TimeType
Definition: StopWatch.h:242
OpenMS::StopWatch
StopWatch Class.
Definition: StopWatch.h:59
OpenMS::StopWatch::start_user_time_
TimeType start_user_time_
Definition: StopWatch.h:255
OpenMS::StopWatch::is_running_
bool is_running_
Definition: StopWatch.h:246
String.h
OpenMS::StopWatch::current_usecs_
PointerSizeInt current_usecs_
Definition: StopWatch.h:264
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::StopWatch::current_user_time_
TimeType current_user_time_
Definition: StopWatch.h:267
OpenMS::StopWatch::current_system_time_
TimeType current_system_time_
Definition: StopWatch.h:270
OpenMS::StopWatch::start_usecs_
PointerSizeInt start_usecs_
Definition: StopWatch.h:252
OpenMS::StopWatch::cpu_speed_
static PointerSizeInt cpu_speed_
Definition: StopWatch.h:236
KDTree::operator==
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806