measure.hpp 884 B

1234567891011121314151617181920212223242526272829
  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. #ifndef BOOST_HANA_BENCHMARK_MEASURE_HPP
  5. #define BOOST_HANA_BENCHMARK_MEASURE_HPP
  6. #include <chrono>
  7. #include <iostream>
  8. namespace boost { namespace hana { namespace benchmark {
  9. auto measure = [](auto f) {
  10. constexpr auto repetitions = 500ull;
  11. auto start = std::chrono::steady_clock::now();
  12. for (auto i = repetitions; i > 0; --i) {
  13. f();
  14. }
  15. auto stop = std::chrono::steady_clock::now();
  16. auto time = std::chrono::duration_cast<std::chrono::duration<float>>(
  17. (stop - start) / repetitions
  18. );
  19. std::cout << std::fixed;
  20. std::cout << "[execution time: " << time.count() << "]" << std::endl;
  21. };
  22. }}}
  23. #endif