1 // boost/chrono/timer.hpp ------------------------------------------------------------//
3 // Copyright Beman Dawes 2008
4 // Copyright 2009 Vicente J. Botet Escriba
6 // Distributed under the Boost Software License, Version 1.0. (See accompanying
7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/system for documentation.
11 #ifndef BOOSTEX_CHRONO_TIMER_HPP
12 #define BOOSTEX_CHRONO_TIMER_HPP
14 #include <boost/chrono/chrono.hpp>
15 #include <boost/system/error_code.hpp>
22 //--------------------------------------------------------------------------------------//
24 //--------------------------------------------------------------------------------------//
26 template <class Clock=boost::chrono::high_resolution_clock>
31 typedef typename Clock::duration duration;
32 typedef typename Clock::time_point time_point;
34 explicit timer( boost::system::error_code & ec = BOOST_CHRONO_THROWS )
39 ~timer() {} // never throws
41 void start( boost::system::error_code & ec = BOOST_CHRONO_THROWS )
43 m_start = clock::now( ec );
46 duration elapsed( boost::system::error_code & ec = BOOST_CHRONO_THROWS )
47 { return clock::now( ec ) - m_start; }
53 typedef chrono::timer< boost::chrono::system_clock > system_timer;
54 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
55 typedef chrono::timer< boost::chrono::steady_clock > steady_timer;
57 typedef chrono::timer< boost::chrono::high_resolution_clock > high_resolution_timer;
60 } // namespace boost_ex