Remove sleep.h dependency for tests

This commit is contained in:
Kai Wolf 2016-05-02 19:53:45 +02:00
parent f352c30f1c
commit fb733897c5
2 changed files with 10 additions and 6 deletions

View File

@ -1,9 +1,5 @@
# Enable the tests
# Allow the test files to find headers in src/ since we rely on
# SleepForMilliseconds(int milliseconds) in options_test.cc
include_directories(${PROJECT_SOURCE_DIR}/src)
find_package(Threads REQUIRED)
set(CXX03_FLAGS "${CMAKE_CXX_FLAGS}")

View File

@ -1,5 +1,7 @@
#include "benchmark/benchmark_api.h"
#include "sleep.h"
#include <chrono>
#include <thread>
void BM_basic(benchmark::State& state) {
while (state.KeepRunning()) {
@ -7,8 +9,14 @@ 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)
};
while (state.KeepRunning()) {
benchmark::SleepForMilliseconds(state.range_x());
std::this_thread::sleep_for(sleep_duration);
}
}