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)


benchmark.pedantic(target, args=(), kwargs=None, setup=None, rounds=1, warmup_rounds=0, iterations=1)
  • target (callable) – Function to benchmark.
  • args (list or tuple) – Positional arguments to the target function.
  • kwargs (dict) – Named arguments to the target function.
  • setup (callable) –

    A function to call right before calling the target function.

    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)


    if you use a setup function then you cannot use the args, kwargs and iterations options.

  • 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')) the iterations is 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=10 then your function will be called 50 times.