Switch sr-arithmetic benchmarking to criterion - #3902
Conversation
Indeed. My personal opinion is that: criterion is great but let's not refactor to it just for the sake of refactoring. Criterion is great when you want to pass complex data to the benchmark. This is something that from this perspective,
of course, this is my personal opinion and how I would like to spend my time. You can go ahead and do more if you want. Nonetheless, thanks for the arithmetic benchmarks that would be very helpful now or in the future! :) |
kianenigma
left a comment
There was a problem hiding this comment.
I think it can use criterion a bit more and remove almost-duplicated-code. Regarding the rest, I would be happier to approve this earlier and not jump into refactoring every single #[bench], but the author can decide otherwise. Thanks :)
|
The reason I want to see this change Ty for the pr! :) |
Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>
|
|
||
| fn bench_subtraction(c: &mut Criterion) { | ||
| bench_op(c, "subtraction", |a, b| { | ||
| let _ = a.clone().sub(&b); |
There was a problem hiding this comment.
| let _ = a.clone().sub(&b); | |
| let _ = a.clone().sub(&b); |
better to have let _ = .. consistently for all or none.
| let a = random_big_uint(size as usize); | ||
| let b = random_big_uint(size as usize); | ||
|
|
||
| bencher.iter(|| op(&a, &b)); |
There was a problem hiding this comment.
hmm I just ran it and being amazed of why division is as fast as addition: we don't do division p / q if the size of q is equal to p. Need to be reworked. I'd leave it up to you regarding how to bake it out of criterion, but ideally, given p with size limbs, we should chose a secondary random number between [2, size-1] and build a number of that size and divide them.
kianenigma
left a comment
There was a problem hiding this comment.
Needs a small rework of the division
|
@expenses done and review needed? please update the labels as needed :) |
|
I don't think I can set labels, sorry. |
kianenigma
left a comment
There was a problem hiding this comment.
looks good! CI is a bit overloaded now so will merge later.
As mentioned by @bkchr and @kianenigma in #3799, we should try and use criterion for benchmarking where possible. I wanted to replace all old
#[bench]benchmarks with criterion in this pr, but unfortunately the subkey benchmarks aren't exposed, the node executor benchmarks require an unwanted amount of code duplication and the phragmen benchmarks are complied via a macro. I'm not sure it's worth it to try and convert these benchmarks at the moment.I did rename the core/primitives benchmark file from
benches.rstobench.rsto be more consistent though.substrate/subkey/src/vanity.rs
Lines 163 to 173 in eda5fe5
substrate/node/executor/src/lib.rs
Lines 1215 to 1230 in eda5fe5
substrate/core/phragmen/benches/phragmen.rs
Lines 158 to 174 in eda5fe5