Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] Refactor RunBenchmark() #690

Merged
merged 3 commits into from
Oct 1, 2018

Conversation

LebedevRI
Copy link
Collaborator

Ok, so, i'm still trying to get to the state when it will be a trivial change to report all the separate iterations.
The old code (LHS of the diff) was rather convoluted i'd say.
I have tried to refactor it a bit into small logical chunks, with proper comments.
As far as i can tell, i preserved the intent of the code, what it was doing before.
The road forward still isn't clear, but i'm quite sure it's not with the old code :)

@coveralls
Copy link

coveralls commented Sep 25, 2018

Coverage Status

Coverage increased (+0.2%) to 89.256% when pulling b3ec1c8 on LebedevRI:refactor-RunBenchmark into edc77a3 on google:master.

@AppVeyorBot
Copy link

Build benchmark 1470 failed (commit 93720b92ec by @LebedevRI)

@AppVeyorBot
Copy link

Build benchmark 1471 failed (commit b7ef961139 by @LebedevRI)

src/benchmark.cc Outdated Show resolved Hide resolved
src/benchmark.cc Outdated
}

return run_results;
RunResults getResults() { return run_results; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm torn between this, where you have a simple accessor but the constructor is complex and actually doing the work, and an alternative where the constructor merely initialises the state, and a method Run that runs the benchmark and returns RunResults.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i don't like this, too.
The current approach (complex constructor) seems better,
because we really wouldn't want to re-run re-use
the same BenchmarkRunner instance more than once.

@dmah42
Copy link
Member

dmah42 commented Sep 26, 2018

This seems to work really well. I wonder if it's worth extracting the class into a benchmark_runner.cc implementation file to help reduce the overwhelming benchmark.cc file size.

@LebedevRI
Copy link
Collaborator Author

This seems to work really well.

Well, it should be the same algo, just less, convoluted?

I wonder if it's worth extracting the class into a benchmark_runner.cc implementation file to help reduce the overwhelming benchmark.cc file size.

Done, better?

src/benchmark_runner.cc Show resolved Hide resolved
src/benchmark_api_internal.h Outdated Show resolved Hide resolved
@AppVeyorBot
Copy link

Build benchmark 1487 failed (commit c356a2f34d by @LebedevRI)

@LebedevRI
Copy link
Collaborator Author

Anything more to do here?

From my side, all the follow-up work in benchmark_runner.cc will be in follow-up pr,
once i'm aware what it is..

@AppVeyorBot
Copy link

Build benchmark 1494 failed (commit c7a3c9277c by @LebedevRI)

@AppVeyorBot
Copy link

Build benchmark 1495 completed (commit fdd6be7f6c by @LebedevRI)

}
}

RunResults getResults() { return run_results; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

google-style: get_results()

also, mark the method as const?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even the current non-const variant is not what i wanted..
https://godbolt.org/z/7ALmcF

size_t iters;
double seconds;
};
IterationResults doNIterations() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DoNIterations

return i;
}

size_t predictNumItersNeeded(const IterationResults& i) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PredictNumItersNeeded

return next_iters; // round up before conversion to integer.
}

bool shouldReportIterationResults(const IterationResults& i) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ShouldReportIterationResults

((i.results.real_time_used >= 5 * min_time) && !b.use_manual_time);
}

void doOneRepetition(bool is_the_first_repetition) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DoOneRepetition

@@ -170,7 +170,7 @@ class BenchmarkRunner {
}
}

RunResults getResults() { return run_results; }
RunResults&& get_results() { return std::move(run_results); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch :) that's much better.

@LebedevRI
Copy link
Collaborator Author

Thank you for the review!

@AppVeyorBot
Copy link

Build benchmark 1504 completed (commit ac305f101c by @LebedevRI)

@LebedevRI LebedevRI merged commit a8082de into google:master Oct 1, 2018
@LebedevRI LebedevRI deleted the refactor-RunBenchmark branch October 1, 2018 14:51
JBakamovic pushed a commit to JBakamovic/benchmark that referenced this pull request Dec 6, 2018
Ok, so, i'm still trying to get to the state when it will be a trivial change to report all the separate iterations.
The old code (LHS of the diff) was rather convoluted i'd say.
I have tried to refactor it a bit into *small* logical chunks, with proper comments.
As far as i can tell, i preserved the intent of the code, what it was doing before.
The road forward still isn't clear, but i'm quite sure it's not with the old code :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants