Created
May 6, 2009 01:28
-
-
Save doitian/107314 to your computer and use it in GitHub Desktop.
ClockTimer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @file utility/ClockTimer.h | |
* | |
* Created <2009-03-02 16:37:39 Ian Yang> | |
* Last Updated <2009-03-02 16:37:45 Ian Yang> | |
*/ | |
#ifndef UTILITY_CLOCK_TIMER_H | |
#define UTILITY_CLOCK_TIMER_H | |
#include <boost/date_time/posix_time/posix_time.hpp> | |
namespace util { | |
class ClockTimer | |
{ | |
public: | |
ClockTimer() | |
: start_(boost::posix_time::microsec_clock::local_time()) | |
{} | |
void restart() | |
{ | |
start_ = boost::posix_time::microsec_clock::local_time(); | |
} | |
double elapsed() const | |
{ | |
boost::posix_time::time_duration td = | |
boost::posix_time::microsec_clock::local_time() - | |
start_; | |
return static_cast<double>(td.fractional_seconds()) / | |
boost::posix_time::time_duration::ticks_per_second() | |
+ td.total_seconds(); | |
} | |
private: | |
boost::posix_time::ptime start_; | |
}; | |
} // namespace util | |
#endif // UTILITY_CLOCK_TIMER_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment