mirror of
https://github.com/google/benchmark.git
synced 2025-01-28 04:40:17 +08:00
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:
parent
354b14d1a0
commit
df9ab80113
@ -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 =
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user