Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_SYSTEM_STOPWATCH_H
00036 #define OPENMS_SYSTEM_STOPWATCH_H
00037
00038 #include <OpenMS/config.h>
00039
00040 #include <OpenMS/CONCEPT/Types.h>
00041 #include <OpenMS/DATASTRUCTURES/String.h>
00042
00043 #ifdef OPENMS_HAS_SYS_TIME_H
00044 #include <sys/time.h>
00045 #endif
00046
00047 #ifdef OPENMS_HAS_TIME_H
00048 #include <ctime>
00049 #endif
00050
00051 #include <iostream>
00052
00053 namespace OpenMS
00054 {
00062 class OPENMS_DLLAPI StopWatch
00063 {
00064 public:
00065
00069
00073 StopWatch();
00074
00078 StopWatch(const StopWatch & stop_watch);
00079
00083 virtual ~StopWatch();
00084
00086
00089
00094 void clear();
00095
00101 bool start();
00102
00108 bool stop();
00109
00114 void reset();
00115
00117
00121
00125 DoubleReal getClockTime() const;
00126
00130 DoubleReal getUserTime() const;
00131
00135 DoubleReal getSystemTime() const;
00136
00141 inline DoubleReal getCPUTime() const
00142 {
00143 return getUserTime() + getSystemTime();
00144 }
00145
00147
00151
00157 StopWatch & operator=(const StopWatch & stop_watch);
00158
00160
00164
00168 bool isRunning() const
00169 {
00170 return is_running_;
00171 }
00172
00180 bool operator==(const StopWatch & stop_watch) const;
00181
00189 inline bool operator!=(const StopWatch & stop_watch) const
00190 {
00191 return !(*this == stop_watch);
00192 }
00193
00200 inline bool operator<(const StopWatch & stop_watch) const
00201 {
00202 return getCPUTime() < stop_watch.getCPUTime();
00203 }
00204
00211 inline bool operator<=(const StopWatch & stop_watch) const
00212 {
00213 return !(stop_watch < *this);
00214 }
00215
00222 inline bool operator>=(const StopWatch & stop_watch) const
00223 {
00224 return !(*this < stop_watch);
00225 }
00226
00233 inline bool operator>(const StopWatch & stop_watch) const
00234 {
00235 return stop_watch < *this;
00236 }
00237
00239
00243 static String toString(DoubleReal time);
00244
00245 private:
00246
00247 static PointerSizeInt cpu_speed_;
00248
00249 #ifdef OPENMS_WINDOWSPLATFORM
00250 static PointerSizeInt clock_speed_;
00251 typedef OPENMS_UINT64_TYPE TimeType;
00252 #else
00253 typedef clock_t TimeType;
00254 #endif
00255
00256
00257 bool is_running_;
00258
00259
00260 PointerSizeInt start_secs_;
00261
00262
00263 PointerSizeInt start_usecs_;
00264
00265
00266 TimeType start_user_time_;
00267
00268
00269 TimeType start_system_time_;
00270
00271
00272 PointerSizeInt current_secs_;
00273
00274
00275 PointerSizeInt current_usecs_;
00276
00277
00278 TimeType current_user_time_;
00279
00280
00281 TimeType current_system_time_;
00282 };
00283
00284 }
00285
00286 #endif // OPENMS_SYSTEM_STOPWATCH_H