mirror of
https://github.com/google/benchmark.git
synced 2025-03-31 06:30:35 +08:00
add walltime benchmark and fix unused variable.
This commit is contained in:
parent
be993acbb3
commit
725f1f066d
@ -145,16 +145,12 @@ WallTimeImp::WallTimeImp()
|
|||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
// WallTimeImp doesn't work when CPU Scaling is enabled. If CPU Scaling is
|
WallTime CPUWalltimeNow() {
|
||||||
// enabled at the start of the program then std::chrono::system_clock is used
|
|
||||||
// instead.
|
|
||||||
WallTime Now()
|
|
||||||
{
|
|
||||||
static bool useWallTime = !CpuScalingEnabled();
|
|
||||||
if (useWallTime) {
|
|
||||||
static WallTimeImp& imp = WallTimeImp::GetWallTimeImp();
|
static WallTimeImp& imp = WallTimeImp::GetWallTimeImp();
|
||||||
return imp.Now();
|
return imp.Now();
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
WallTime ChronoWalltimeNow() {
|
||||||
typedef std::chrono::system_clock Clock;
|
typedef std::chrono::system_clock Clock;
|
||||||
typedef std::chrono::duration<WallTime, std::chrono::seconds::period>
|
typedef std::chrono::duration<WallTime, std::chrono::seconds::period>
|
||||||
FPSeconds;
|
FPSeconds;
|
||||||
@ -163,6 +159,18 @@ WallTime Now()
|
|||||||
auto now = Clock::now().time_since_epoch();
|
auto now = Clock::now().time_since_epoch();
|
||||||
return std::chrono::duration_cast<FPSeconds>(now).count();
|
return std::chrono::duration_cast<FPSeconds>(now).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WallTimeImp doesn't work when CPU Scaling is enabled. If CPU Scaling is
|
||||||
|
// enabled at the start of the program then std::chrono::system_clock is used
|
||||||
|
// instead.
|
||||||
|
WallTime Now()
|
||||||
|
{
|
||||||
|
static bool useWallTime = !CpuScalingEnabled();
|
||||||
|
if (useWallTime) {
|
||||||
|
return CPUWalltimeNow();
|
||||||
|
} else {
|
||||||
|
return ChronoWalltimeNow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace walltime
|
} // end namespace walltime
|
||||||
@ -185,6 +193,7 @@ std::string DateTimeString(bool local) {
|
|||||||
}
|
}
|
||||||
std::size_t written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
|
std::size_t written = std::strftime(storage, sizeof(storage), "%F %T", &timeinfo);
|
||||||
CHECK(written < arraysize(storage));
|
CHECK(written < arraysize(storage));
|
||||||
|
((void)written); // prevent unused variable in optimized mode.
|
||||||
return std::string(storage);
|
return std::string(storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@ namespace benchmark {
|
|||||||
typedef double WallTime;
|
typedef double WallTime;
|
||||||
|
|
||||||
namespace walltime {
|
namespace walltime {
|
||||||
|
WallTime CPUWalltimeNow();
|
||||||
|
WallTime ChronoWalltimeNow();
|
||||||
WallTime Now();
|
WallTime Now();
|
||||||
} // end namespace walltime
|
} // end namespace walltime
|
||||||
|
|
||||||
|
@ -32,3 +32,5 @@ compile_benchmark_test(cxx03_test)
|
|||||||
set_target_properties(cxx03_test
|
set_target_properties(cxx03_test
|
||||||
PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}")
|
PROPERTIES COMPILE_FLAGS "${CXX03_FLAGS}")
|
||||||
add_test(cxx03 cxx03_test)
|
add_test(cxx03 cxx03_test)
|
||||||
|
|
||||||
|
compile_benchmark_test(walltime_test)
|
||||||
|
@ -65,8 +65,8 @@ void BM_pause_during(benchmark::State& state) {
|
|||||||
state.ResumeTiming();
|
state.ResumeTiming();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BENCHMARK_TEST(BM_pause_during);
|
BENCHMARK(BM_pause_during);
|
||||||
BENCHMARK_TEST(BM_pause_during)->ThreadPerCpu();
|
BENCHMARK(BM_pause_during)->ThreadPerCpu();
|
||||||
|
|
||||||
void BM_pause_during_realtime(benchmark::State& state) {
|
void BM_pause_during_realtime(benchmark::State& state) {
|
||||||
state.UseRealTime();
|
state.UseRealTime();
|
||||||
@ -75,8 +75,8 @@ void BM_pause_during_realtime(benchmark::State& state) {
|
|||||||
state.ResumeTiming();
|
state.ResumeTiming();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BENCHMARK_TEST(BM_pause_during_realtime);
|
BENCHMARK(BM_pause_during_realtime);
|
||||||
BENCHMARK_TEST(BM_pause_during_realtime)->ThreadPerCpu();
|
BENCHMARK(BM_pause_during_realtime)->ThreadPerCpu();
|
||||||
|
|
||||||
void BM_spin_pause_after(benchmark::State& state) {
|
void BM_spin_pause_after(benchmark::State& state) {
|
||||||
while(state.KeepRunning()) {
|
while(state.KeepRunning()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user