mirror of
https://github.com/google/benchmark.git
synced 2025-04-29 06:20:32 +08:00
address more review comments
This commit is contained in:
parent
8f86de1562
commit
83beb03e00
@ -156,17 +156,6 @@ void Initialize(int* argc, const char** argv);
|
||||
// and exit after running the benchmarks.
|
||||
void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter = NULL);
|
||||
|
||||
// ------------------------------------------------------
|
||||
// Routines that can be called from within a benchmark
|
||||
|
||||
//
|
||||
// REQUIRES: a benchmark is currently executing
|
||||
void SetLabel(const char* label);
|
||||
|
||||
inline void SetLabel(std::string const & label) {
|
||||
SetLabel(label.c_str());
|
||||
}
|
||||
|
||||
// If this routine is called, peak memory allocation past this point in the
|
||||
// benchmark is reported at the end of the benchmark report line. (It is
|
||||
// computed by running the benchmark once with a single iteration and a memory
|
||||
@ -174,14 +163,6 @@ inline void SetLabel(std::string const & label) {
|
||||
// TODO(dominic)
|
||||
// void MemoryUsage();
|
||||
|
||||
// If a particular benchmark is I/O bound, or if for some reason CPU
|
||||
// timings are not representative, call this method from within the
|
||||
// benchmark routine. If called, the elapsed time will be used to
|
||||
// control how many iterations are run, and in the printing of
|
||||
// items/second or MB/seconds values. If not called, the cpu time
|
||||
// used by the benchmark will be used.
|
||||
void UseRealTime();
|
||||
|
||||
namespace internal {
|
||||
class Benchmark;
|
||||
class BenchmarkFamilies;
|
||||
@ -242,6 +223,14 @@ public:
|
||||
// within each benchmark iteration, if possible.
|
||||
void ResumeTiming();
|
||||
|
||||
// If a particular benchmark is I/O bound, or if for some reason CPU
|
||||
// timings are not representative, call this method from within the
|
||||
// benchmark routine. If called, the elapsed time will be used to
|
||||
// control how many iterations are run, and in the printing of
|
||||
// items/second or MB/seconds values. If not called, the cpu time
|
||||
// used by the benchmark will be used.
|
||||
void UseRealTime();
|
||||
|
||||
// Set the number of bytes processed by the current benchmark
|
||||
// execution. This routine is typically called once at the end of a
|
||||
// throughput oriented benchmark. If this routine is called with a
|
||||
|
@ -724,8 +724,15 @@ void State::ResumeTiming() {
|
||||
timer_manager->StartTimer();
|
||||
}
|
||||
|
||||
void State::UseRealTime() {
|
||||
MutexLock l(GetBenchmarkLock());
|
||||
use_real_time = true;
|
||||
}
|
||||
|
||||
void State::SetLabel(const char* label) {
|
||||
::benchmark::SetLabel(label);
|
||||
CHECK(running_benchmark);
|
||||
MutexLock l(GetBenchmarkLock());
|
||||
*GetReportLabel() = label;
|
||||
}
|
||||
|
||||
BenchmarkReporter::~BenchmarkReporter() {}
|
||||
@ -888,17 +895,6 @@ void RunSpecifiedBenchmarks(const BenchmarkReporter* reporter) {
|
||||
internal::RunMatchingBenchmarks(spec, reporter ? reporter : &default_reporter);
|
||||
}
|
||||
|
||||
void SetLabel(const char* label) {
|
||||
CHECK(running_benchmark);
|
||||
MutexLock l(GetBenchmarkLock());
|
||||
*GetReportLabel() = label;
|
||||
}
|
||||
|
||||
void UseRealTime() {
|
||||
MutexLock l(GetBenchmarkLock());
|
||||
use_real_time = true;
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
||||
void PrintUsageAndExit() {
|
||||
|
@ -53,18 +53,22 @@ static void BM_Factorial(benchmark::State& state) {
|
||||
while (state.KeepRunning())
|
||||
fac_42 = Factorial(8);
|
||||
// Prevent compiler optimizations
|
||||
std::cout << fac_42;
|
||||
std::stringstream ss;
|
||||
ss << fac_42;
|
||||
state.SetLabel(ss.str());
|
||||
}
|
||||
BENCHMARK(BM_Factorial);
|
||||
|
||||
static void BM_FactorialRealTime(benchmark::State& state) {
|
||||
benchmark::UseRealTime();
|
||||
state.UseRealTime();
|
||||
|
||||
int fac_42 = 0;
|
||||
while (state.KeepRunning())
|
||||
fac_42 = Factorial(8);
|
||||
// Prevent compiler optimizations
|
||||
std::cout << fac_42;
|
||||
std::stringstream ss;
|
||||
ss << fac_42;
|
||||
state.SetLabel(ss.str());
|
||||
}
|
||||
BENCHMARK(BM_FactorialRealTime);
|
||||
|
||||
@ -158,12 +162,5 @@ static void BM_LongTest(benchmark::State& state) {
|
||||
}
|
||||
BENCHMARK(BM_LongTest)->Range(1<<16,1<<28);
|
||||
|
||||
int main(int argc, const char* argv[]) {
|
||||
benchmark::Initialize(&argc, argv);
|
||||
|
||||
assert(Factorial(8) == 40320);
|
||||
assert(CalculatePi(1) == 0.0);
|
||||
|
||||
benchmark::RunSpecifiedBenchmarks();
|
||||
}
|
||||
BENCHMARK_MAIN()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user