From e1c01b91fdd5f8ddd002b33534f0b0b7c3678eea Mon Sep 17 00:00:00 2001 From: Michael Simacek Date: Wed, 1 Jul 2026 16:19:47 +0200 Subject: [PATCH] Restore JIT warmup calibration default --- doc/api.rst | 2 +- doc/runner.rst | 4 ++-- pyperf/_runner.py | 2 +- pyperf/tests/test_runner.py | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/doc/api.rst b/doc/api.rst index cb08ebed..96e1ed0f 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -517,7 +517,7 @@ HookBase class Runner class ------------ -.. class:: Runner(values=3, warmups=1, processes=20, loops=0, min_time=0.1, metadata=None, show_name=True, program_args=None, add_cmdline_args=None, hooks=None) +.. class:: Runner(values=3, warmups=None, processes=20, loops=0, min_time=0.1, metadata=None, show_name=True, program_args=None, add_cmdline_args=None, hooks=None) Tool to run a benchmark in text mode. diff --git a/doc/runner.rst b/doc/runner.rst index 6e9dbf4c..8b899e93 100644 --- a/doc/runner.rst +++ b/doc/runner.rst @@ -22,7 +22,7 @@ Default without JIT (ex: CPython): 20 processes, 3 values per process (total: 60 values), and 1 warmup. Default with a JIT (ex: PyPy): 6 processes, 10 values per process (total: 60 -values), and 10 warmups. +values), and automatic warmup calibration. * ``--rigorous``: Spend longer running tests to get more accurate results. Multiply the number of ``PROCESSES`` by 2. Default: 40 processes and 3 @@ -35,7 +35,7 @@ values), and 10 warmups. * ``VALUES``: number of values per process (default: ``3``, or ``10`` with a JIT) * ``WARMUPS``: the number of ignored values used to warmup to benchmark - (default: ``1``, or ``10`` with a JIT) + (default: ``1``, or automatically calibrated with a JIT) * ``LOOPS``: number of loops per value. ``x^y`` syntax is accepted, example: ``--loops=2^8`` uses ``256`` iterations. By default, the timer is calibrated to get raw values taking at least ``MIN_TIME`` seconds. diff --git a/pyperf/_runner.py b/pyperf/_runner.py index 3a7ab11d..d0828888 100644 --- a/pyperf/_runner.py +++ b/pyperf/_runner.py @@ -77,7 +77,7 @@ def __init__(self, values=None, processes=None, loops=0, min_time=0.1, metadata=None, show_name=True, program_args=None, add_cmdline_args=None, - _argparser=None, warmups=1, hooks=None): + _argparser=None, warmups=None, hooks=None): # Watchdog: ensure that only once instance of Runner (or a Runner # subclass) is created per process to prevent bad surprises diff --git a/pyperf/tests/test_runner.py b/pyperf/tests/test_runner.py index c77e0251..2234108e 100644 --- a/pyperf/tests/test_runner.py +++ b/pyperf/tests/test_runner.py @@ -85,6 +85,21 @@ def test_debug_single_value(self): result = self.exec_runner('--debug-single-value', '--worker') self.assertEqual(result.bench.get_nvalue(), 1) + def test_default_warmups_without_jit(self): + with mock.patch('pyperf.python_has_jit', return_value=False): + runner = self.create_runner([]) + self.assertEqual(runner.args.warmups, 1) + + def test_default_warmups_with_jit(self): + with mock.patch('pyperf.python_has_jit', return_value=True): + runner = self.create_runner([]) + self.assertIsNone(runner.args.warmups) + + def test_runner_warmups_argument(self): + with mock.patch('pyperf.python_has_jit', return_value=True): + runner = self.create_runner([], warmups=5) + self.assertEqual(runner.args.warmups, 5) + def test_profile_time_func(self): with tempfile.NamedTemporaryFile('wb+') as tmp: name = tmp.name