From 7ab5c2d0380a4c9f32e8141def7d9e41bfdb315d Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Sun, 12 Jun 2011 18:47:00 +0300 Subject: [PATCH] Replaced boost timer implementation with gettimeofday and GetSystemTimeAsFileTime --- base/base.pro | 1 + base/timer.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ base/timer.hpp | 30 ++++++++++++------------------ 3 files changed, 54 insertions(+), 18 deletions(-) create mode 100644 base/timer.cpp diff --git a/base/base.pro b/base/base.pro index ae2dd355fc..bbc5bbfa6d 100644 --- a/base/base.pro +++ b/base/base.pro @@ -23,6 +23,7 @@ SOURCES += \ lower_case.cpp \ normalize_unicode.cpp \ runner.cpp \ + timer.cpp \ HEADERS += \ SRC_FIRST.hpp \ diff --git a/base/timer.cpp b/base/timer.cpp new file mode 100644 index 0000000000..c544447624 --- /dev/null +++ b/base/timer.cpp @@ -0,0 +1,41 @@ +#include "timer.hpp" + +#include "../std/target_os.hpp" +#include "../std/time.hpp" + +namespace my +{ + +Timer::Timer() +{ + Reset(); +} + +double Timer::LocalTime() const +{ +#ifdef OMIM_OS_WINDOWS + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + uint64_t val = ft.dwHighDateTime; + val <<= 32; + val += ft.dwLowDateTime; + return val / 10000000.0; + +#else + timeval tv; + gettimeofday(&tv, 0); + return tv.tv_sec + tv.tv_usec / 1000000.0; +#endif +} + +double Timer::ElapsedSeconds() const +{ + return LocalTime() - m_startTime; +} + +void Timer::Reset() +{ + m_startTime = LocalTime(); +} + +} diff --git a/base/timer.hpp b/base/timer.hpp index e74f2d81e0..d08c5eb30e 100644 --- a/base/timer.hpp +++ b/base/timer.hpp @@ -1,25 +1,19 @@ #pragma once -#include "base.hpp" - -#define BOOST_DATE_TIME_NO_LIB -#include namespace my { - /// Cross platform timer - class Timer - { - public: - Timer() { Reset(); } - double ElapsedSeconds() const - { - return (boost::posix_time::microsec_clock::local_time() - m_StartTime).total_milliseconds() - / 1000.0; - } - void Reset() { m_StartTime = boost::posix_time::microsec_clock::local_time(); } - private: - boost::posix_time::ptime m_StartTime; - }; +/// Cross platform timer +class Timer +{ + double m_startTime; + + double LocalTime() const; + +public: + Timer(); + double ElapsedSeconds() const; + void Reset(); +}; }