Commit c5f45495 by Eric Fiselier

Workaround missing std::this_thread::sleep_for function in tests.

GCC 4.7 doesn't provide std::this_thread::sleep_for on my system. This patch changes the tests to use a different method for wasting cycles.
parent ebd37b19
...@@ -186,9 +186,11 @@ static void BM_ManualTiming(benchmark::State& state) { ...@@ -186,9 +186,11 @@ static void BM_ManualTiming(benchmark::State& state) {
while (state.KeepRunning()) { while (state.KeepRunning()) {
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();
// Simulate some useful workload with a sleep // Simulate some useful workload by sleeping.
std::this_thread::sleep_for(std::chrono::duration_cast< // Note: std::this_thread::sleep_for doesn't work with GCC 4.7 on some
std::chrono::nanoseconds>(sleep_duration)); // platforms.
const auto sleep_end = std::chrono::steady_clock::now() + sleep_duration;
while (std::chrono::steady_clock::now() < sleep_end) {}
auto end = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now();
auto elapsed = auto elapsed =
......
...@@ -11,9 +11,11 @@ void BM_basic(benchmark::State& state) { ...@@ -11,9 +11,11 @@ void BM_basic(benchmark::State& state) {
void BM_basic_slow(benchmark::State& state) { void BM_basic_slow(benchmark::State& state) {
std::chrono::milliseconds sleep_duration(state.range_x()); std::chrono::milliseconds sleep_duration(state.range_x());
while (state.KeepRunning()) { while (state.KeepRunning()) {
std::this_thread::sleep_for( // Simulate some useful workload by sleeping.
std::chrono::duration_cast<std::chrono::nanoseconds>(sleep_duration) // Note: std::this_thread::sleep_for doesn't work with GCC 4.7 on some
); // platforms.
const auto sleep_end = std::chrono::steady_clock::now() + sleep_duration;
while (std::chrono::steady_clock::now() < sleep_end) {}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment