LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiTimer.h

00001 /*
00002  * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*----------------------------------------------------------------
00025  * project ....: LTI Digital Image/Signal Processing Library
00026  * file .......: ltiTimer.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 12.06.00
00030  * revisions ..: $Id: ltiTimer.h,v 1.5 2006/02/08 12:55:15 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_TIMER_H
00034 #define _LTI_TIMER_H
00035 
00036 #include "ltiObject.h"
00037 #include <string>
00038 
00039 namespace lti {
00040 
00041   /**
00042    * This global function is a replacement in the %lti namespace for
00043    * the sleep and Sleep functions of Windows and Unix.  To avoid
00044    * misunderstanding the name has been changed to passiveWait.  The
00045    * time must always be given in microseconds, although the real
00046    * precision will be determined by the operating system.  (Windows
00047    * uses milliseconds and Unixes a few microseconds, depending on the
00048    * implementation of usleep.
00049    *
00050    * @param usTime number of microseconds to wait
00051    */
00052   void passiveWait(const int& usTime);
00053 
00054   /** The timer allows to measure time with a precision of about 30us on
00055       Linux systems and ??? on windows systems.
00056 
00057       The maximum time that can be measured with this function is 1 day
00058       (86.4E+09 microseconds).  To measure longer time intervalls use the
00059       standard time() function.
00060 
00061       Note that this function returns the Wall-Clock time and not the CPU-Time.
00062 
00063       Example:
00064 
00065       \code
00066 
00067       lti::timer chron;
00068 
00069       chron.start();
00070 
00071       // do something
00072 
00073       chron.stop();
00074 
00075       std::cout << "something takes " << chron.getTime() << " microseconds\n";
00076 
00077       \endcode
00078   */
00079   class timer : public object {
00080   public:
00081     /// default constructor
00082     timer();
00083 
00084     /// start the timer
00085     void start();
00086 
00087     /// stop the timer
00088     void stop();
00089 
00090     /** get the elapsed time (in microsecond) between start() and stop() or the
00091         actual time (if stop() is not been called yet!)
00092 
00093         @return elapsed time
00094      */
00095     double getTime() const;
00096 
00097     /// name of this type
00098     virtual const char* getTypeName() const;
00099 
00100     static std::string getDateAndTime();
00101 
00102   protected:
00103     double startTime;
00104     double endTime;
00105     bool started;
00106 
00107     // get actual time
00108     double getActualTime() const;
00109 
00110     // only for MS VC++ version
00111 # ifdef _LTI_WIN32
00112   private:
00113     // 2^32
00114     static const double max32bit;
00115     // frequency (Hz) of the performance counter
00116     double freq;
00117 # endif
00118 
00119   };
00120 }
00121 
00122 #endif

Generated on Sat Apr 10 15:26:17 2010 for LTI-Lib by Doxygen 1.6.1