From 46afd8e69339b546526706056da9dd5009fa01f1 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Tue, 18 Apr 2017 00:13:18 -0600 Subject: [PATCH] Don't limit benchmarks with manual timers to 5x the elapsed real time. When using CPU time to determine the correct number of iterations the library additionally checks if the benchmark has consumed 5x the minimum required time according to the wall clock. This prevents benchmarks with low CPU usage from running for much longer than actually intended. However when a benchmark uses a manual timer this heuristic isn't helpful and likely isn't correct since we don't know what the manual timer actually measures. This patch removes the above restriction when a benchmark specifies a manual timer. --- src/benchmark.cc | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/benchmark.cc b/src/benchmark.cc index 4adb97ac..00ffa07f 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -296,7 +296,7 @@ std::vector RunBenchmark( (b.report_mode == internal::RM_Unspecified ? FLAGS_benchmark_report_aggregates_only : b.report_mode == internal::RM_ReportAggregatesOnly); - for (int i = 0; i < repeats; i++) { + for (int repetition_num = 0; repetition_num < repeats; repetition_num++) { for (;;) { // Try benchmark VLOG(2) << "Running " << b.name << " for " << iters << "\n"; @@ -332,11 +332,20 @@ std::vector RunBenchmark( const double min_time = !IsZero(b.min_time) ? b.min_time : FLAGS_benchmark_min_time; - // If this was the first run, was elapsed time or cpu time large enough? - // If this is not the first run, go with the current value of iter. - if ((i > 0) || has_explicit_iteration_count || results.has_error_ || - (iters >= kMaxIterations) || - (seconds >= min_time) || (results.real_time_used >= 5 * min_time)) { + + // Determine if this run should be reported; Either it has + // run for a sufficient amount of time or because an error was reported. + const bool should_report = repetition_num > 0 + || has_explicit_iteration_count // An exact iteration count was requested + || results.has_error_ + || iters >= kMaxIterations + || seconds >= min_time // the elapsed time is large enough + // CPU time is specified but the elapsed real time greatly exceeds the + // minimum time. Note that user provided timers are except from this + // sanity check. + || ((results.real_time_used >= 5 * min_time) && !b.use_manual_time); + + if (should_report) { BenchmarkReporter::Run report = CreateRunReport(b, results, iters, seconds); if (!report.error_occurred && b.complexity != oNone)