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

StopWatch.h (Maintainer: Oliver Kohlbacher)

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework 
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Oliver Kohlbacher $
00025 // --------------------------------------------------------------------------
00026 //
00027 
00028 #ifndef OPENMS_SYSTEM_STOPWATCH_H
00029 #define OPENMS_SYSTEM_STOPWATCH_H
00030 
00031 #include <OpenMS/config.h>
00032 
00033 #include <OpenMS/CONCEPT/Types.h>
00034 
00035 #ifdef OPENMS_HAS_SYS_TIME_H
00036 #include <sys/time.h>
00037 #endif
00038 
00039 #ifdef OPENMS_HAS_TIME_H
00040 #include <time.h>
00041 #endif
00042 
00043 #include <iostream>
00044 
00045 namespace OpenMS
00046 {
00054   class StopWatch
00055   {
00056     public:
00057     
00061 
00065     StopWatch();              
00066 
00070     StopWatch(const StopWatch& stop_watch);             
00071 
00075     virtual ~StopWatch();
00076 
00078 
00081 
00086     void clear();     
00087   
00093     bool start();     
00094 
00100     bool stop();
00101 
00106     void reset();
00107 
00109       
00113 
00117     DoubleReal getClockTime() const;
00118 
00122     DoubleReal getUserTime() const;   
00123 
00127     DoubleReal getSystemTime() const;
00128 
00133     inline DoubleReal getCPUTime() const throw()
00134     { 
00135       return (getUserTime() + getSystemTime());
00136     }
00137 
00138 
00140 
00144 
00150     StopWatch& operator = (const StopWatch& stop_watch);
00151 
00153 
00157 
00161     bool isRunning() const throw()
00162     {
00163       return is_running_;
00164     }
00165 
00173     bool operator == (const StopWatch& stop_watch) const;
00174 
00182     inline bool operator != (const StopWatch& stop_watch) const throw()
00183     {
00184       return !(*this == stop_watch);
00185     }
00186 
00187 
00194     inline bool operator < (const StopWatch& stop_watch) const throw()
00195     {
00196       return (getCPUTime() < stop_watch.getCPUTime());
00197     }
00198 
00199 
00206     inline bool operator <= (const StopWatch& stop_watch) const throw()
00207     {
00208       return !(stop_watch < *this);
00209     }
00210 
00211 
00218     inline bool operator >= (const StopWatch& stop_watch) const throw()
00219     {
00220       return !(*this < stop_watch);
00221     }
00222 
00223 
00230     inline bool operator > (const StopWatch& stop_watch) const throw()
00231     {
00232       return (stop_watch < *this);
00233     }
00234 
00235 
00237 
00238 
00239     private:
00240 
00241     static PointerSizeInt cpu_speed_;
00242 
00243     #ifdef OPENMS_HAS_WINDOWS_PERFORMANCE_COUNTER
00244       static PointerSizeInt clock_speed_;
00245     #endif
00246 
00247     // state of stop watch, either true(on) or false(off) 
00248     bool is_running_;
00249 
00250     // clock seconds value when the stop watch was last started 
00251     PointerSizeInt last_secs_;  
00252 
00253     // clock useconds value when the stop watch was last started 
00254     PointerSizeInt last_usecs_;   
00255 
00256     // user time when the stop watch was last started 
00257     clock_t last_user_time_;   
00258 
00259     // system time when the stop watch was last started 
00260     clock_t last_system_time_; 
00261      
00262     // current accumulated clock seconds 
00263     PointerSizeInt current_secs_;   
00264 
00265     // current accumulated clock useconds 
00266     PointerSizeInt current_usecs_;    
00267     
00268     // current accumulated user time 
00269     clock_t current_user_time_;   
00270 
00271     // current accumulated user time 
00272     clock_t current_system_time_;
00273   };
00274 
00275 }
00276 
00277 #endif // OPENMS_SYSTEM_STOPWATCH_H

Generated Tue Apr 1 15:36:38 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1