1 2 // Copyright Oliver Kowalke 2009. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 // 7 #ifndef CLOCK_H 8 #define CLOCK_H 9 10 #include <algorithm> 11 #include <cstddef> 12 #include <numeric> 13 #include <vector> 14 15 #include <boost/assert.hpp> 16 #include <boost/chrono.hpp> 17 #include <boost/cstdint.hpp> 18 19 typedef boost::chrono::high_resolution_clock clock_type; 20 typedef clock_type::duration duration_type; 21 typedef clock_type::time_point time_point_type; 22 23 struct clock_overhead 24 { operator ()clock_overhead25 boost::uint64_t operator()() 26 { 27 time_point_type start( clock_type::now() ); 28 return ( clock_type::now() - start).count(); 29 } 30 }; 31 overhead_clock()32duration_type overhead_clock() 33 { 34 std::size_t iterations( 10); 35 std::vector< boost::uint64_t > overhead( iterations, 0); 36 for ( std::size_t i = 0; i < iterations; ++i) 37 std::generate( 38 overhead.begin(), overhead.end(), 39 clock_overhead() ); 40 BOOST_ASSERT( overhead.begin() != overhead.end() ); 41 return duration_type( std::accumulate( overhead.begin(), overhead.end(), 0) / iterations); 42 } 43 44 #endif // CLOCK_H 45