]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // high_res_clock.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~ | |
4 | // | |
b32b8144 | 5 | // Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
6 | // |
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) | |
9 | // | |
10 | ||
11 | #ifndef HIGH_RES_CLOCK_HPP | |
12 | #define HIGH_RES_CLOCK_HPP | |
13 | ||
14 | #include <boost/config.hpp> | |
15 | #include <boost/cstdint.hpp> | |
16 | ||
17 | #if defined(BOOST_ASIO_WINDOWS) | |
18 | ||
19 | inline boost::uint64_t high_res_clock() | |
20 | { | |
21 | LARGE_INTEGER i; | |
22 | QueryPerformanceCounter(&i); | |
23 | return i.QuadPart; | |
24 | } | |
25 | ||
26 | #elif defined(__GNUC__) && defined(__x86_64__) | |
27 | ||
28 | inline boost::uint64_t high_res_clock() | |
29 | { | |
30 | unsigned long low, high; | |
31 | __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)); | |
32 | return (((boost::uint64_t)high) << 32) | low; | |
33 | } | |
34 | ||
35 | #else | |
36 | ||
37 | #include <boost/date_time/posix_time/posix_time_types.hpp> | |
38 | ||
39 | inline boost::uint64_t high_res_clock() | |
40 | { | |
41 | boost::posix_time::ptime now = | |
42 | boost::posix_time::microsec_clock::universal_time(); | |
43 | ||
44 | boost::posix_time::ptime epoch( | |
45 | boost::gregorian::date(1970, 1, 1), | |
46 | boost::posix_time::seconds(0)); | |
47 | ||
48 | return (now - epoch).total_microseconds(); | |
49 | } | |
50 | ||
51 | #endif | |
52 | ||
53 | #endif // HIGH_RES_CLOCK_HPP |