Open jvesely opened 2 years ago
I encountered this problem when benchmarking a function which mutates its own input arguments. The first run, this mutation had a side effect, but on subsequent runs, the mutation wasn't necessary, and so the side effect was not observed.
Workaround is to encpasulate this function in a wrapper that deepcopies any initial state and provides the copy to the stateful function to mutate.
use the benchmark_safe wrapper on the benchmark
call instead.
The current behaviour is to return the last result of multiple iterations. This makes testing stateful functions difficult. For example:
The above snippet only passes with
--benchmark-disable
and fails with benchmarks enabled. I know it's possible to get the number of executions from the benchmark object, but the expected result might not be as easy to calculate as above.one alternative is:
but that complains/warns that the benchmark fixture is unused so the correct workaround would be