/*============================================================================= Copyright (c) 2005 Hartmut Kaiser Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #if !defined(BOOST_HIGH_RESOLUTION_TIMER_HPP) #define BOOST_HIGH_RESOLUTION_TIMER_HPP #include #if !defined(BOOST_WINDOWS) // For platforms other than Windows, simply fall back to boost::timer #include namespace boost { typedef boost::timer high_resolution_timer; } #else #include #include #include namespace boost { /////////////////////////////////////////////////////////////////////////////// // // high_resolution_timer // A timer object measures elapsed time. // CAUTION: Windows only! // /////////////////////////////////////////////////////////////////////////////// class high_resolution_timer { public: high_resolution_timer() { start_time.QuadPart = 0; frequency.QuadPart = 0; if (!QueryPerformanceFrequency(&frequency)) throw std::runtime_error("Couldn't aquire frequency"); restart(); } void restart() { if (!QueryPerformanceCounter(&start_time)) throw std::runtime_error("Couldn't initialise start_time"); } double elapsed() const // return elapsed time in seconds { LARGE_INTEGER now; if (!QueryPerformanceCounter(&now)) throw std::runtime_error("Couldn't get current time"); return double(now.QuadPart - start_time.QuadPart) / frequency.QuadPart; } double elapsed_max() const // return estimated maximum value for elapsed() { return (double((std::numeric_limits::max)()) - double(start_time.QuadPart)) / double(frequency.QuadPart); } double elapsed_min() const // return minimum value for elapsed() { return 1.0 / frequency.QuadPart; } private: LARGE_INTEGER start_time; LARGE_INTEGER frequency; }; } // namespace boost #endif // !defined(BOOST_WINDOWS) #endif // !defined(BOOST_HIGH_RESOLUTION_TIMER_HPP)