Skip to content

Commit

Permalink
Replace int Benchmark::calculateLoops(int) with bool Benchmark::shoul…
Browse files Browse the repository at this point in the history
…dLoop().

Given that this method and all its overrides return either 1 or the given number of loops, let's replace it with a method that returns a boolean.

Motivation:

- Less confusing.
- Simplifies the BenchmarkBazelRunner.cpp program I'm working on (see https://skia-review.googlesource.com/c/skia/+/762118).

Bug: b/40045301
Change-Id: I8b2a35c525d3945218b6ae3020a92a8230ac124a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/761737
Reviewed-by: John Stiles <[email protected]>
Commit-Queue: Leandro Lovisolo <[email protected]>
Auto-Submit: Leandro Lovisolo <[email protected]>
  • Loading branch information
LeandroLovisolo authored and SkCQ committed Oct 3, 2023
1 parent b708dd7 commit c66c89c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions bench/Benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ class Benchmark : public SkRefCnt {
// Allows a benchmark to override options used to construct the GrContext.
virtual void modifyGrContextOptions(GrContextOptions*) {}

virtual int calculateLoops(int defaultLoops) const {
return defaultLoops;
// Whether or not this benchmark requires multiple samples to get a meaningful result.
virtual bool shouldLoop() const {
return true;
}

// Call before draw, allows the benchmark to do setup work outside of the
Expand Down
4 changes: 2 additions & 2 deletions bench/SKPBench.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class SKPBench : public Benchmark {
bool doLooping);
~SKPBench() override;

int calculateLoops(int defaultLoops) const override {
return fDoLooping ? defaultLoops : 1;
bool shouldLoop() const override {
return fDoLooping;
}

void getGpuStats(SkCanvas*,
Expand Down
4 changes: 2 additions & 2 deletions bench/SkSLBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ class SkSLModuleLoaderBench : public Benchmark {
return backend == kNonRendering_Backend;
}

int calculateLoops(int defaultLoops) const override {
return 1;
bool shouldLoop() const override {
return false;
}

void onPreDraw(SkCanvas*) override {
Expand Down
4 changes: 2 additions & 2 deletions bench/nanobench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ static int setup_cpu_bench(const double overhead, Target* target, Benchmark* ben
// First figure out approximately how many loops of bench it takes to make overhead negligible.
double bench_plus_overhead = 0.0;
int round = 0;
int loops = bench->calculateLoops(FLAGS_loops);
int loops = bench->shouldLoop() ? FLAGS_loops : 1;
if (kAutoTuneLoops == loops) {
while (bench_plus_overhead < overhead) {
if (round++ == FLAGS_maxCalibrationAttempts) {
Expand Down Expand Up @@ -509,7 +509,7 @@ static int setup_cpu_bench(const double overhead, Target* target, Benchmark* ben

static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) {
// First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
int loops = bench->calculateLoops(FLAGS_loops);
int loops = bench->shouldLoop() ? FLAGS_loops : 1;
if (kAutoTuneLoops == loops) {
loops = 1;
double elapsed = 0;
Expand Down

0 comments on commit c66c89c

Please sign in to comment.