1 // Copyright Louis Dionne 2013-2017 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 4 5 #ifndef BOOST_HANA_BENCHMARK_MEASURE_HPP 6 #define BOOST_HANA_BENCHMARK_MEASURE_HPP 7 8 #include <chrono> 9 #include <iostream> 10 11 12 namespace boost { namespace hana { namespace benchmark { __anon6fb0737f0102(auto f) 13 auto measure = [](auto f) { 14 constexpr auto repetitions = 500ull; 15 auto start = std::chrono::steady_clock::now(); 16 for (auto i = repetitions; i > 0; --i) { 17 f(); 18 } 19 auto stop = std::chrono::steady_clock::now(); 20 21 auto time = std::chrono::duration_cast<std::chrono::duration<float>>( 22 (stop - start) / repetitions 23 ); 24 std::cout << std::fixed; 25 std::cout << "[execution time: " << time.count() << "]" << std::endl; 26 }; 27 }}} 28 29 #endif 30