Compare timings in nanoseconds for sub-microsecond precision - #23
Merged
Conversation
Result parsed timeit's output into a datetime.timedelta, whose resolution bottoms out at one microsecond. For sub-microsecond exercises -- e.g. the name-normalization work in python/importlib_metadata#533 -- both the control and experiment rounded to timedelta(0), collapsing the variance calculation to 0/0 and rendering any regression or improvement invisible. Parse instead with tempora.parse_nanoseconds, keeping durations as a Decimal count of nanoseconds so the delta and variance stay meaningful at any scale. Because the values are no longer timedeltas, format the reported experiment and delta with timeit's own units (nsec/usec/msec/sec) rather than timedelta's H:MM:SS rendering. Closes #18. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jaraco
commented
Jul 13, 2026
jaraco
commented
Jul 13, 2026
jaraco
commented
Jul 13, 2026
jaraco
commented
Jul 13, 2026
jaraco
commented
Jul 13, 2026
jaraco
commented
Jul 13, 2026
….signed Rework the previous commit's approach in response to review. Parsing to a bare Decimal count of nanoseconds retained the needed precision but reduced a duration to a scalar with implied units, and left the unit formatting -- which isn't pytest-perf's concern -- living here. Parse instead into a tempora.Duration (5.12): a nanosecond-resolution timedelta that carries its own magnitude and units, divides by another Duration to yield the variance ratio directly, and renders itself in timeit's natural units (nsec/µsec/msec/sec). The reported delta gets its sign from jaraco.functools.signed (4.6), replacing a boolean flag on the formatter. variance returns to a try/except, and all duration formatting leaves this module. Requires tempora 5.12 (Duration) and jaraco.functools 4.6 (signed). Closes #18. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jaraco
commented
Jul 14, 2026
Add a doctest exercising Result: parsing, delta, variance (including the zero-control branches that return inf or 0), and rendering. Inline the signed delta formatter into __str__ rather than binding it at module scope. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jaraco
force-pushed
the
feature/sub-microsecond-precision
branch
from
July 14, 2026 09:04
18bb5cf to
8b9151f
Compare
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.
Closes #18
Problem
Resultparsed timeit's output into adatetime.timedelta, whose resolution bottoms out at one microsecond. For sub-microsecond exercises — e.g. the name-normalization work in python/importlib_metadata#533 — both the control and experiment rounded totimedelta(0), collapsingvariance = (experiment - control) / controlto0/0and rendering any regression or improvement invisible.Fix
Parse with the new
tempora.parse_nanoseconds(jaraco/tempora#49, released in tempora 5.11), keeping durations as aDecimalcount of nanoseconds so the delta and variance stay meaningful at any scale. Since the values are no longer timedeltas,Result.__str__now formats the experiment and delta with timeit's own units (nsec/usec/msec/sec) instead of timedelta'sH:MM:SSrendering.Result
The suite's own perf exercises now report meaningful sub-microsecond numbers where they previously would have been
timedelta(0):Bumps the
temporafloor to>=5.11forparse_nanoseconds. Full suite green locally against tempora 5.11.0.🤖 Generated with Claude Code