Enable UseRealTime and fix documentation for SetLabel.
Fixes #89
UseRealTime was defined in the internal namespace by mistake.
Similarly, documentation suggested that benchmark::SetLabel should be
used to set a label, and a function was declared but not defined, while
actually the call should be 'state.SetLabel'.
diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h
index 2532454..5da915e 100644
--- a/include/benchmark/benchmark.h
+++ b/include/benchmark/benchmark.h
@@ -158,10 +158,6 @@
// ------------------------------------------------------
// Routines that can be called from within a benchmark
-//
-// REQUIRES: a benchmark is currently executing
-void SetLabel(const std::string& label);
-
// 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
@@ -212,10 +208,10 @@
// If this routine is called, the specified label is printed at the
// end of the benchmark report line for the currently executing
// benchmark. Example:
- // static void BM_Compress(int iters) {
+ // static void BM_Compress(benchmark::State& state) {
// ...
// double compress = input_size / output_size;
- // benchmark::SetLabel(StringPrintf("compress:%.1f%%", 100.0*compression));
+ // state.SetLabel(StringPrintf("compress:%.1f%%", 100.0*compression));
// }
// Produces output that looks like:
// BM_Compress 50 50 14115038 compress:27.3%
diff --git a/src/benchmark.cc b/src/benchmark.cc
index 3dd7b63..d4f6f1b 100644
--- a/src/benchmark.cc
+++ b/src/benchmark.cc
@@ -416,8 +416,6 @@
}
*/
-void UseRealTime() { use_real_time = true; }
-
void PrintUsageAndExit() {
fprintf(stdout,
"benchmark [--benchmark_filter=<regex>]\n"
@@ -1176,6 +1174,8 @@
spec, reporter == nullptr ? &default_reporter : reporter);
}
+void UseRealTime() { use_real_time = true; }
+
void Initialize(int* argc, const char** argv) {
internal::ParseCommandLineFlags(argc, argv);
internal::SetLogLevel(FLAGS_v);
diff --git a/test/benchmark_test.cc b/test/benchmark_test.cc
index ec49fcd..2ce1001 100644
--- a/test/benchmark_test.cc
+++ b/test/benchmark_test.cc
@@ -57,6 +57,17 @@
}
BENCHMARK(BM_Factorial);
+static void BM_FactorialRealTime(benchmark::State& state) {
+ benchmark::UseRealTime();
+
+ int fac_42 = 0;
+ while (state.KeepRunning())
+ fac_42 = Factorial(8);
+ // Prevent compiler optimizations
+ std::cout << fac_42;
+}
+BENCHMARK(BM_FactorialRealTime);
+
static void BM_CalculatePiRange(benchmark::State& state) {
double pi = 0.0;
while (state.KeepRunning())