I came across this basic example in the substrate repo, where a range 1..1000
is used when benchmarking it. The generated weights.rs
shows
fn set_dummy_benchmark(b: u32, ) -> Weight {
Weight::from_ref_time(5_834_000 as u64)
.saturating_add(Weight::from_ref_time(24_000 as u64).saturating_mul(b as u64))
.saturating_add(T::DbWeight::get().writes(1 as u64))
}
I've got two questions:
Isn't that a bit counterintuitive? I understand the whole benchmarking will finally build a linear model, but why would
set_dummy(1)
andset_dummy(1000)
make such a big difference? I mean thesaturating_mul(b as u64)
part: ifb
is big enough it can consume a significant amount of weights? OKb
is set to be 1000 max, but I thought it was as simple as updating storage with an integer(or alike) so it should be constant?If there's no such range variance, I could imagine the benchmarking outcome would be constant. So which one is correct? And which one should we follow in real practice? I'm just concerned that defining the upper bound for every value would be infeasible..