Context
As described in https://github.com/martinus/nanobench/issues/130, we have a few benchmarks where we have to reset the state between runs, otherwise the repetitions will do something else than the first iteration.
Upstream
I have opened a PR to nanobench to introduce an untimed setup phase, see: https://github.com/martinus/nanobench/pull/136
Unfortunately the author has health issues and couldn’t contribute to it in the past 2 years.
Tests
Tests were only added upstream, would be a bit awkward to wire in nanobench.h outside the benchmarking setup:
https://github.com/martinus/nanobench/pull/136/changes/58350cfe5912d7e0533ccfcd759eea5d62eb55bb#diff-88160f647ce57661afe7d755fa70a5fa342a2b79d72d3511596878e69ed5cdc3
Fix
I have moved the changes here as well and applied it to a few simple benchmarks as demonstration.
We can revert ones that are controversial and add other ones in follow-ups, this PR is mostly meant to add the setup feature.
Benchmarks
Most benchmarks show a modest “speedup”, others a “slowdown” - but it’s only the effect of the setup that’s not measured anymore - and a run phase which does the same operation in each epoch iteration (wallet benchmark changes were reverted since for simplicity):