Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

StopWatch.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Chris Bielow $
00032 // $Authors: Marc Sturm, Chris Bielow $
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; // do not use clock_t on Windows, since its not big enough for larger time intervalls
00252 #else
00253     typedef clock_t TimeType;
00254 #endif
00255 
00256     // state of stop watch, either true(on) or false(off)
00257     bool is_running_;
00258 
00259     // clock seconds value when the stop watch was last started
00260     PointerSizeInt start_secs_;
00261 
00262     // clock useconds value when the stop watch was last started
00263     PointerSizeInt start_usecs_;
00264 
00265     // user time when the stop watch was last started
00266     TimeType start_user_time_;
00267 
00268     // system time when the stop watch was last started
00269     TimeType start_system_time_;
00270 
00271     // current accumulated clock seconds
00272     PointerSizeInt current_secs_;
00273 
00274     // current accumulated clock useconds
00275     PointerSizeInt current_usecs_;
00276 
00277     // current accumulated user time
00278     TimeType current_user_time_;
00279 
00280     // current accumulated user time
00281     TimeType current_system_time_;
00282   };
00283 
00284 }
00285 
00286 #endif // OPENMS_SYSTEM_STOPWATCH_H

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:45 using doxygen 1.7.1