mirror of
https://github.com/google/benchmark.git
synced 2024-11-25 22:47:20 +00:00
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.
This commit is contained in:
parent
74b24058ad
commit
46afd8e693
|
@ -296,7 +296,7 @@ std::vector<BenchmarkReporter::Run> 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<BenchmarkReporter::Run> 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)
|
||||
|
|
Loading…
Reference in a new issue