5 // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef HIGH_RES_CLOCK_HPP
12 #define HIGH_RES_CLOCK_HPP
14 #include <boost/config.hpp>
15 #include <boost/cstdint.hpp>
17 #if defined(BOOST_ASIO_WINDOWS)
19 inline boost::uint64_t high_res_clock()
22 QueryPerformanceCounter(&i);
26 #elif defined(__GNUC__) && defined(__x86_64__)
28 inline boost::uint64_t high_res_clock()
30 unsigned long low, high;
31 __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high));
32 return (((boost::uint64_t)high) << 32) | low;
37 #include <boost/date_time/posix_time/posix_time_types.hpp>
39 inline boost::uint64_t high_res_clock()
41 boost::posix_time::ptime now =
42 boost::posix_time::microsec_clock::universal_time();
44 boost::posix_time::ptime epoch(
45 boost::gregorian::date(1970, 1, 1),
46 boost::posix_time::seconds(0));
48 return (now - epoch).total_microseconds();
53 #endif // HIGH_RES_CLOCK_HPP