Skip to content

Commit

Permalink
Clean up the initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenarnst committed Jan 25, 2024
1 parent b79ae2c commit 55ff633
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
43 changes: 34 additions & 9 deletions src/benchmark_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -326,24 +326,33 @@ IterationCount BenchmarkRunner::PredictNumItersNeeded(
// expansion should be 14x.
const bool is_significant = (i.seconds / GetMinTimeToApply()) > 0.1;
multiplier = is_significant ? multiplier : 10.0;

if (!IsZero(GetMinRelAccuracy())) {
multiplier = std::max(multiplier, std::sqrt(i.seconds2 / i.iters - std::pow(i.seconds / i.iters, 2.)) / (i.seconds / i.iters) / sqrt(i.iters) * 1.4 / GetMinRelAccuracy());
multiplier = std::max(multiplier, GetRelAccuracy(i) * 1.4 / GetMinRelAccuracy());
}

// So what seems to be the sufficiently-large iteration count? Round up.
const IterationCount max_next_iters = static_cast<IterationCount>(
std::lround(std::max(multiplier * static_cast<double>(i.iters),
static_cast<double>(i.iters) + 1.0)));
// But we do have *some* limits though..
const IterationCount next_iters = std::min(max_next_iters, kMaxIterations);

BM_VLOG(3) << "Next iters: " << next_iters << ", " << multiplier << "\n";
return next_iters; // round up before conversion to integer.
}

bool BenchmarkRunner::ShouldReportIterationResults(
const IterationResults& i) const {
// Determine if this run should be reported;
// Either it has run for a sufficient amount of time
// or because an error was reported.
return i.results.skipped_ ||
i.iters >= kMaxIterations || // Too many iterations already.
(((i.seconds >= GetMinTimeToApply()) &&
(b.use_manual_time() && !IsZero(GetMinRelAccuracy()) && (std::sqrt(i.seconds2 / i.iters - std::pow(i.seconds / i.iters, 2.)) / (i.seconds / i.iters) / sqrt(i.iters) <= GetMinRelAccuracy()))) || // The relative accuracy is enough.
// CPU time is specified but the elapsed real time greatly exceeds
// the minimum time.
// Note that user provided timers are except from this test.
((i.results.real_time_used >= 5 * GetMinTimeToApply()) &&
!b.use_manual_time()));
// Too many iterations already.
i.iters >= kMaxIterations ||
// We have applied for enough time and the relative accuracy is good enough.
// Relative accuracy is checked only for user provided timers.
(HasSufficientTimeToApply(i) && (!b.use_manual_time() || HasSufficientRelAccuracy(i)));
}

double BenchmarkRunner::GetMinTimeToApply() const {
Expand All @@ -355,6 +364,22 @@ double BenchmarkRunner::GetMinTimeToApply() const {
return warmup_done ? min_time : min_warmup_time;
}

double GetRelAccuracy(const IterationResults& i) const {
return std::sqrt(i.seconds2 / i.iters - std::pow(i.seconds / i.iters, 2.)) / (i.seconds / i.iters) / sqrt(i.iters);
}

bool BenchmarkRunner::HasSufficientTimeToApply(const IterationResults& i) const {
return i.seconds >= GetMinTimeToApply() ||
// CPU time is specified but the elapsed real time greatly exceeds
// the minimum time.
// Note that user provided timers are except from this test.
(!b.use_manual_time() && i.results.real_time_used >= 5 * GetMinTimeToApply());
}

bool BenchmarkRunner::HasSufficientRelAccuracy(const IterationResults& i) const {
return (!IsZero(GetMinRelAccuracy()) && (GetRelAccuracy(i) <= GetMinRelAccuracy()));
}

void BenchmarkRunner::FinishWarmUp(const IterationCount& i) {
warmup_done = true;
iters = i;
Expand Down
6 changes: 6 additions & 0 deletions src/benchmark_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ class BenchmarkRunner {

double GetMinTimeToApply() const;

double GetRelAccuracy(const IterationResults& i) const;

bool HasSufficientTimeToApply(const IterationResults& i) const;

bool HasSufficientRelAccuracy(const IterationResults& i) const;

void FinishWarmUp(const IterationCount& i);

void RunWarmUp();
Expand Down

0 comments on commit 55ff633

Please sign in to comment.