Skip to content

Instantly share code, notes, and snippets.

@doitian
Created May 6, 2009 01:28
Show Gist options
  • Save doitian/107314 to your computer and use it in GitHub Desktop.
Save doitian/107314 to your computer and use it in GitHub Desktop.
ClockTimer.h
/**
* @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