Repository navigation
Conversation
timeit runs setup once then the statement N times. Stateful setup() must re-run between samples; with number>1 (auto or explicit) the stmt mutates state without re-setup (asv#966). When any setup hooks are registered, pin number=1 so each sample is one call and redo_setup runs between samples.
|
Documentation preview for this PR: documentation.zip. Unzip and open |
This was referenced Aug 4, 2026
kraktus
reviewed
Aug 4, 2026
| # re-setup. Benchmarks with a setup() that restores state need | ||
| # number=1 so each sample is one call (setup between samples via | ||
| # redo_setup). See asv#966. | ||
| if self._setups and number != 1: |
There was a problem hiding this comment.
Would make sense to warn the user than its number is not taken into account.
Member
Author
There was a problem hiding this comment.
The merged design honors an explicit number instead of overriding it: with setup hooks present it batches through per-call timing with setup interleaved between the calls, so nothing is silently dropped. Auto-calibration with setup hooks resolves to number=1, which the docs spell out (airspeed-velocity/asv#1608). Added a stderr note when the interleaved path engages so the changed methodology is visible in benchmark output: 3538c94.
Warmup suppresses redo_setup to stay cheap; with setup hooks present that hands every warmup call the state mutated by the previous one, which is the failure reported for explicit number=1 in asv#966. Keep the suppression only when no setup hooks exist, so warmup observes the same freshly-set-up state as the measurement loop.
Pinning number=1 for every benchmark with a setup hook turns fast benchmarks with benign input-building setups into single-shot samples at timer granularity and makes the number attribute dead. Pin only when number is auto (0): the asv#966 reproducer uses auto number and stays fixed, while an explicit number keeps timeit batching for authors who accept shared state within a sample. Timeraw samples run in fresh subprocesses, so TimerawBenchmark opts out of the pinning.
Run the asv#966 reproducer under default CPython warmup instead of warmup_time=0, which masked the warmup-loop state reuse. Add explicit number=1 (warmup semantics) and number=7 (batching preserved with a benign setup) cases, and require auto calibration to pick number>1 without setup hooks.
An explicit number > 1 with setup hooks previously shared state mutated by earlier calls within the sample. Route that case through a timeit-compatible batch timer that re-runs setup (redo_setup) before every call and accumulates only the calls, with gc disabled per sample to match timeit. Costs two clock reads per call, which only explicit batching with setup hooks pays; auto calibration still resolves to number=1 under plain timeit and hook-free benchmarks are unchanged.
The packaged __init__.py is generated by pdm-backend (write_to) and carries a static __version__; the in-repo file was empty, so editable and sys.path imports had no __version__ at all and no-scm tarball builds fell back to 0.0.0. Resolve the installed distribution version via importlib.metadata with a 0.0.0.dev0 fallback; built artifacts still get the static string.
Both build jobs uploaded a v4 artifact under the default name 'artifact'; same-named v4 artifacts from parallel jobs are distinct objects and the name-filtered download in upload_pypi took only one, so v0.2.5 reached PyPI wheel-only and downstream packagers fell back to GitHub archive tarballs that carry no scm version. Name the artifacts, merge them into dist/ for publishing, and fetch full history so pdm-backend describes a real version on branch builds.
This was referenced Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes airspeed-velocity/asv#966 for the runner side.
timeit.Timer(stmt, setup=redo_setup).timeit(number=N)runs setup once,then the statement N times: setup was per sample, never between the
inner calls, and warmup suppressed it entirely. With setup hooks
present, every timed call now observes freshly set-up state:
loop. This was the remaining failure for explicit
number=1reportedin the issue thread.
numberresolves to 1 under plaintimeit.number > 1batches through a timeit-compatibletimer that re-runs setup before every call and accumulates only the
calls (gc disabled per sample, matching timeit), at the cost of two
clock reads per call.
setup_cacheremains the batching path for input-building setups.
timerawopts out: each of its samples is a fresh subprocess.Also fixes
asv_runner.__version__for source-tree imports: thein-repo
__init__.pywas empty (pdm-backend writes the static versiononly into built artifacts), so editable installs had no
__version__and no-scm tarball builds fell back to 0.0.0. It now resolves the
installed distribution version with a
0.0.0.dev0fallback.Also fixes release publishing: both build jobs uploaded a v4 artifact
under the default name
artifact, and the name-filtered download inupload_pypitook only one of them, so v0.2.5 reached PyPI wheel-only(downstream packagers then built from GitHub archive tarballs, which
carry no scm version; the conda-forge 0.2.5 artifact ships
__version__ = 0.1.dev24+gf49f9a3). Artifacts are now named and mergedinto
dist/, and checkouts fetch full history so branch builds get areal described version.
Companion docs: airspeed-velocity/asv#1608
Test plan
python -m unittest discover -s tests(25 tests)number=1survives warmup; explicitnumber=10with amutating setup passes and reports
number=10; auto calibration stillpicks
number>1without setup hooksmetadata (or fallback) version