Use nanoseconds instead of duration<double, milli>
MSVC++ before 2015 Update 2 has a bug in sleep_for where it tries to
implicitly += the input with a nanoseconds variable. Work around this by
using nanoseconds directly (which can be implicitly +='d with
chrono::nanoseconds).
diff --git a/test/benchmark_test.cc b/test/benchmark_test.cc
index fa99559..252602a 100644
--- a/test/benchmark_test.cc
+++ b/test/benchmark_test.cc
@@ -186,7 +186,8 @@
while (state.KeepRunning()) {
auto start = std::chrono::high_resolution_clock::now();
// Simulate some useful workload with a sleep
- std::this_thread::sleep_for(sleep_duration);
+ std::this_thread::sleep_for(std::chrono::duration_cast<
+ std::chrono::nanoseconds>(sleep_duration));
auto end = std::chrono::high_resolution_clock::now();
auto elapsed =
diff --git a/test/options_test.cc b/test/options_test.cc
index 4fe2d17..4737caa 100644
--- a/test/options_test.cc
+++ b/test/options_test.cc
@@ -9,14 +9,11 @@
}
void BM_basic_slow(benchmark::State& state) {
-
- int milliseconds = state.range_x();
- std::chrono::duration<double, std::milli> sleep_duration {
- static_cast<double>(milliseconds)
- };
-
+ std::chrono::milliseconds sleep_duration(state.range_x());
while (state.KeepRunning()) {
- std::this_thread::sleep_for(sleep_duration);
+ std::this_thread::sleep_for(
+ std::chrono::duration_cast<std::chrono::nanoseconds>(sleep_duration)
+ );
}
}