1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| #ifndef _nCoreEngine_Timer
#define _nCoreEngine_Timer
#include <boost/date_time/posix_time/posix_time_types.hpp>
namespace nCoreEngine {
class Timer {
private:
boost::posix_time::ptime _startTime;
public:
Timer() : _startTime(boost::posix_time::microsec_clock::local_time()) {}
void restart() {
_startTime = boost::posix_time::ptime(boost::posix_time::microsec_clock::local_time());
}
double elapsed() const { // return seconds with 10E-3 precision
boost::posix_time::ptime now(boost::posix_time::microsec_clock::local_time());
boost::posix_time::time_duration elapsed = now - _startTime;
return elapsed.total_milliseconds()/1000.f;
}
};
} // namespace nCoreEngine
#endif // _nCoreEngine_Timer |