Last active
August 29, 2015 14:07
-
-
Save ldionne/ae1ddf95e7a064d3d27f to your computer and use it in GitHub Desktop.
Support header for runtime benchmarks with the Benchcc gem.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
@copyright Louis Dionne 2014 | |
Distributed under the Boost Software License, Version 1.0. | |
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
*/ | |
#ifndef BOOST_HANA_BENCHMARK_MEASURE_HPP | |
#define BOOST_HANA_BENCHMARK_MEASURE_HPP | |
#include <chrono> | |
#include <iostream> | |
#include <thread> | |
namespace boost { namespace hana { namespace benchmark { | |
template <int i> | |
struct object { | |
constexpr object() = default; | |
object(object const&) { | |
std::this_thread::sleep_for(std::chrono::nanoseconds(1)); | |
} | |
}; | |
auto measure = [](auto f) { | |
constexpr auto repetitions = 1000ull; | |
auto start = std::chrono::steady_clock::now(); | |
for (auto i = repetitions; i > 0; --i) { | |
f(); | |
} | |
auto stop = std::chrono::steady_clock::now(); | |
auto time = std::chrono::duration_cast<std::chrono::microseconds>( | |
(stop - start) / repetitions | |
); | |
std::cout << "execution time: " << time.count() << std::endl; | |
}; | |
}}} | |
#endif // !BOOST_HANA_BENCHMARK_MEASURE_HPP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This file is not used anymore. Instead, Benchmarks.cmake contains a hardcoded version of this file, so it does not have to download it every time CMake is reconfigured. This is left here in case someone uses an old version of Benchmarks.cmake which requires downloading this file, but consider upgrading if this is the case.