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).
parent 354b14d1
...@@ -186,7 +186,8 @@ static void BM_ManualTiming(benchmark::State& state) { ...@@ -186,7 +186,8 @@ 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 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 end = std::chrono::high_resolution_clock::now();
auto elapsed = auto elapsed =
......
...@@ -9,14 +9,11 @@ void BM_basic(benchmark::State& state) { ...@@ -9,14 +9,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());
int milliseconds = state.range_x();
std::chrono::duration<double, std::milli> sleep_duration {
static_cast<double>(milliseconds)
};
while (state.KeepRunning()) { while (state.KeepRunning()) {
std::this_thread::sleep_for(sleep_duration); std::this_thread::sleep_for(
std::chrono::duration_cast<std::chrono::nanoseconds>(sleep_duration)
);
} }
} }
......
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