-
Notifications
You must be signed in to change notification settings - Fork 1.1k
bench: replace wall-clock timer with per-process CPU timer #1732
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
base: master
Are you sure you want to change the base?
Conversation
Just some quick comments:
I think there's a reason to have this. Some benchmarks take much longer than others, so it probably makes sense to run fewer iters for these.
I think
Well, okay, that has a history; see #689. It's debatable if it makes sense to avoid floating point math, but as long as it doesn't get in your way here, it's a cool thing to keep it. :D |
It will be useful to split your changes into meaningful and separate commits, see https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#committing-patches. |
I think |
If we're going to rework this, I'd suggest using the stabilized quartiles approach from https://cr.yp.to/papers/rsrst-20250727.pdf:
|
6aff035
to
d456fad
Compare
right now all benchmarks are run with count=10 and fixed iters (apart from ecmult_multi which adjusts the number of iters, not count). therefore |
I disagree with #689. It overcomplicate things for the sake of not having floating point math. those divisions aren't even in the hot path, they're outside the benchmarks. |
Concept NACK on removing any ability to observe variance in timing. The current min/avg/max are far from perfect, but they work fairly well in practice. Improving is welcome, but removing them is a step backwards. |
what is the usefulness of measuring min/max when we are removing OS interference & thermal throttling out of the equation? min/max will be extremely close to the avg no matter how bad the benchmarked function is. |
97e5264
to
254a014
Compare
1d9d6d0
to
4c9a074
Compare
by the way, |
ddeaede
to
71dff3f
Compare
even though the manual says that I added a line in the README.md for best practices to run the benchmarks. I also tried adding a function to pin the process to a core directly in C, but there's no standard POSIX compliant way to do so. There is |
3e43c75
to
ef9e40e
Compare
The point is exactly having a simple way of verifying that there's indeed no interference. Getting rid of sources of variance is hard to get right, and it's impossible to get a perfect solution. (This discussion shows this!) So we better have a way of spotting if something is off. I like the stabilized quartiles idea. |
tbh it scares me a bit, will see what I can do. Maybe in a future PR. |
ef9e40e
to
66745f7
Compare
f41048e
to
bc556d8
Compare
Not sure. I suggest making this PR focused on a single (uncontroversial) change, which is switching to per process clocks. |
bc556d8
to
b13faa5
Compare
5540c89
to
f9d2dde
Compare
a5eb2db
to
bbc8bb7
Compare
bbc8bb7
to
6c09cf3
Compare
I've applied the recommended changes and split the PR into multiple commits for simpler diffs |
6c09cf3
to
576f79f
Compare
I haven't investigated this in detail but couldn't find any related issue: were there any efforts to use https://nanobench.ankerl.com like we do in Core instead? That will likely need some adjustments on the benchmarks themselves, but at least we wouldn't be rolling our own framework. |
not familiar with nano bench, but I can see it uses also the user would need to have a c++ compiler, not a big real but I think this repo needs to strictly adhere to c89. |
I realized the windows version I implemented was using a unprecise clock. drafting. will fix. |
576f79f
to
8242f55
Compare
This commit improves the reliability of benchmarks by removing some of the influence of other background running processes. This is achieved by using CPU bound clocks that aren't influenced by interrupts, sleeps, blocked I/O, etc.
8242f55
to
6ec4255
Compare
I changed windows clock to |
nanobench is a framework for benchmarking C++ but this is C. Of course, we could still call our C from C++, but adding C++ to the code base seems a bit overkill to me if if's "just" for the purpose of benchmarks. I agree that using an existing framework may be a good idea, but I'm not aware of any in pure C. |
The purpose would be to standardize the benchmarking to avoid reinventing solutions to problems that aren't strictly related to the purpose of this library. It would also help with trusting the result more, since we already know how that benchmarking library behaves. |
Sorry, I didn't want to be discouraging. I don't think at all that nanobench is a far-fetched idea. And I truly agree that reinventing the wheel is not great. In the end, what counts is the maintenance burden. My main concern with C++ is that I'm not sure how fluent our regular contributors are in C++. (I'm not, but luckily I'm not the only one here.) If the bit of C++ is harder to touch (for us) than this code, then nanobench is not a good idea. If, on the other hand, we have people who can maintain C++, or if we get support from the Core contributors who are familiar with nanobench, then this can be a win. I'd be happy to see a demo/WIP PR but if you feel that this is a lot of work, then it might be a good idea to see what other contributors and maintainers think. |
Goal
This PR refactors the benchmarking functions as per #1701, in order to make benchmarks more deterministic and less influenced by the environvment.
This is achieved by replacing Wall-Clock Timer with Per-Process CPU Timer when possible.