Pedantic mode¶
pytest-benchmark allows a special mode that doesn’t do any automatic calibration. To make it clear it’s only for
people that know exactly what they need it’s called “pedantic”.
def test_with_setup(benchmark):
benchmark.pedantic(stuff, args=(1, 2, 3), kwargs={'foo': 'bar'}, iterations=10, rounds=100)
Reference¶
-
benchmark.pedantic(target, args=(), kwargs=None, setup=None, rounds=1, warmup_rounds=0, iterations=1)¶ Parameters: - target (callable) – Function to benchmark.
- args (list or tuple) – Positional arguments to the
targetfunction. - kwargs (dict) – Named arguments to the
targetfunction. - setup (callable) –
A function to call right before calling the
targetfunction.The setup function can also return the arguments for the function (in case you need to create new arguments every time).
def test_with_setup(benchmark): def setup(): # can optionally return a (args, kwargs) tuple return (1, 2, 3), {'foo': 'bar'} benchmark.pedantic(stuff, setup=setup, rounds=100)
Note
if you use a
setupfunction then you cannot use theargs,kwargsanditerationsoptions. - rounds (int) – Number of rounds to run.
- iterations (int) –
Number of iterations.
In the non-pedantic mode (eg:
benchmark(stuff, 1, 2, 3, foo='bar')) theiterationsis automatically chosen depending on what timer you have. In other words, be careful in what you chose for this option.The default value (
1) is unsafe for benchmarking very fast functions that take under 100μs (100 microseconds). - warmup_rounds (int) –
Number of warmup rounds.
Set to non-zero to enable warmup. Warmup will run with the same number of iterations.
Example: if you have
iteration=5, warmup_rounds=10then your function will be called 50 times.