Skip to content

Instantly share code, notes, and snippets.

@ldionne
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldionne/ae1ddf95e7a064d3d27f to your computer and use it in GitHub Desktop.
Save ldionne/ae1ddf95e7a064d3d27f to your computer and use it in GitHub Desktop.
Support header for runtime benchmarks with the Benchcc gem.
/*
@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
@ldionne
Copy link
Author

ldionne commented Mar 25, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment