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).
This commit is contained in:
Billy Robert O'Neal III 2016-05-10 17:35:36 -07:00
parent 354b14d1a0
commit df9ab80113
2 changed files with 6 additions and 8 deletions

View File

@ -186,7 +186,8 @@ static void BM_ManualTiming(benchmark::State& state) {
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 =

View File

@ -9,14 +9,11 @@ void BM_basic(benchmark::State& state) {
}
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)
);
}
}