1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Timo Sachsenberg $
25
// $Authors: Marc Sturm $
26
// --------------------------------------------------------------------------
28
#ifndef OPENMS_SYSTEM_STOPWATCH_H
29
#define OPENMS_SYSTEM_STOPWATCH_H
31
#include <OpenMS/config.h>
33
#include <OpenMS/CONCEPT/Types.h>
35
#ifdef OPENMS_HAS_SYS_TIME_H
39
#ifdef OPENMS_HAS_TIME_H
48
@brief StopWatch Class.
50
This class is used to determine the current process time.
54
class OPENMS_DLLAPI StopWatch
58
/** @name Constructors and Destructors
62
/** Default constructor.
63
Create a new stop watch. The stop watch is stopped.
68
Create a new stop watch from an existing stop watch.
70
StopWatch(const StopWatch& stop_watch);
73
Destructs a stop watch object.
78
/** Starting, Stopping and Resetting the stop watch
82
/** Clear and stop the stop watch.
83
This sets the stop watch to zero and stops it when running.
88
/** Start the stop watch.
89
The stop watch is started. If the stop watch is already running, <b>false</b>
91
@return bool <b>false</b> if the stop watch was already running, <b>true</b> otherwise
95
/** Stop the stop watch.
96
The stop watch is stopped. If the stop watch was not running, <b>false</b>
98
@return bool <b>false</b> if the was not running, <b>true</b> otherwise
102
/** Clear the stop watch without stopping.
103
The stop watch is cleared, but not stopped (if running).
110
/** @name Readout of the StopWatch
115
Return the accumulated clock (real) time in seconds.
117
DoubleReal getClockTime() const;
120
Return the accumulated user time in seconds.
122
DoubleReal getUserTime() const;
125
Return the accumulated system time in seconds.
127
DoubleReal getSystemTime() const;
130
Return the accumulated CPU time in seconds.
131
CPU time is the sum of user time and system time.
133
inline DoubleReal getCPUTime() const
135
return (getUserTime() + getSystemTime());
145
/** Assignment operator.
146
Assigns a stop watch from another. The two stop watch will then run
148
@return StopWatch <tt>*this</tt>
150
StopWatch& operator = (const StopWatch& stop_watch);
158
/** Return true if the stop watch is running.
159
@return bool <b>true</b> if the stop watch is running, <b>false</b> otherwise
161
bool isRunning() const
166
/** Equality operator.
167
Return <b>true</b> if two stop watchs are equal, i.e. they contain exactly
168
the same time intervals for clock, user and system time and have the
170
@param stop_watch the stop watch to compare with
171
@return bool <b>true</b> on equality, <b>false</b> otherwise
173
bool operator == (const StopWatch& stop_watch) const;
175
/** Inequality operator.
176
Return <b>false</b> if two stop watchs differ in any way, i.e. they differ
177
in either the clock, user, or system time or have a different
179
@param stop_watch the stop watch to compare with
180
@return bool <b>true</b> on inequality, <b>false</b> otherwise
182
inline bool operator != (const StopWatch& stop_watch) const
184
return !(*this == stop_watch);
188
/** Lesser than operator.
189
Return true, if the stop watch is in all timings lesser than the
190
stop watch to be compared with (clock, user and system time).
191
@param stop_watch the stop watch to compare with
192
@return bool <b>true</b> if all times are lesser
194
inline bool operator < (const StopWatch& stop_watch) const
196
return (getCPUTime() < stop_watch.getCPUTime());
200
/** Lesser or equal operator.
201
Return true, if the stop watch is in all timings lesser or equal than the
202
stop watch to be compared with (clock, user and system time).
203
@param stop_watch the stop watch to compare with
204
@return bool <b>true</b> if all times are lesser or equal
206
inline bool operator <= (const StopWatch& stop_watch) const
208
return !(stop_watch < *this);
212
/** Greater or equal operator.
213
Return true, if the stop watch is in all timings greater or equal than the
214
stop watch to be compared with (clock, user and system time).
215
@param stop_watch the stop watch to compare with
216
@return bool <b>true</b> if all times are greater or equal
218
inline bool operator >= (const StopWatch& stop_watch) const
220
return !(*this < stop_watch);
224
/** Greater operator.
225
Return true, if the stop watch is in all timings greater than the
226
stop watch to be compared with (clock, user and system time).
227
@param stop_watch the stop watch to compare with
228
@return bool <b>true</b> if all times are greater
230
inline bool operator > (const StopWatch& stop_watch) const
232
return (stop_watch < *this);
241
static PointerSizeInt cpu_speed_;
243
#ifdef OPENMS_WINDOWSPLATFORM
244
static PointerSizeInt clock_speed_;
247
// state of stop watch, either true(on) or false(off)
250
// clock seconds value when the stop watch was last started
251
PointerSizeInt last_secs_;
253
// clock useconds value when the stop watch was last started
254
PointerSizeInt last_usecs_;
256
// user time when the stop watch was last started
257
clock_t last_user_time_;
259
// system time when the stop watch was last started
260
clock_t last_system_time_;
262
// current accumulated clock seconds
263
PointerSizeInt current_secs_;
265
// current accumulated clock useconds
266
PointerSizeInt current_usecs_;
268
// current accumulated user time
269
clock_t current_user_time_;
271
// current accumulated user time
272
clock_t current_system_time_;
277
#endif // OPENMS_SYSTEM_STOPWATCH_H