Timer.h

Go to the documentation of this file.
00001 /**<!-------------------------------------------------------------------->
00002    @class  Timer
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @author Matthew Jacobs (jacobs.mh@gmail.com)
00005    @date   Fall 2008
00006 
00007    @brief
00008       Small utility timer
00009    
00010    @note
00011       Replaces the functionality of boost::timer which, at least on my primary 
00012    testing system (Fedora i686 Linux), yields drastically incorrect results...
00013    <!-------------------------------------------------------------------->**/
00014 
00015 #ifndef TIMER_H_
00016 #define TIMER_H_
00017 
00018 #include <common/common.h>
00019 #include <sys/time.h>
00020 
00021 struct Timer {
00022    inline Timer() {
00023       reset();
00024    }
00025    
00026    inline void reset() {
00027       gettimeofday(&m_startTime, 0);
00028    }
00029    
00030    /// @returns elapsed time measured in seconds since last reset
00031    inline double elapsed() const {
00032       timeval current_time;
00033       gettimeofday(&current_time, 0);
00034       
00035       current_time.tv_sec  -= m_startTime.tv_sec;
00036       current_time.tv_usec -= m_startTime.tv_usec;
00037       
00038       return current_time.tv_sec + 
00039          double(current_time.tv_usec) / CLOCKS_PER_SEC;
00040    }
00041    
00042    private:
00043       timeval m_startTime;
00044 };
00045 
00046 #endif // TIMER_H_
00047 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6