chore: add self-benchmark suite under benchmarks/#20
Merged
Conversation
Add a yarlpattern-only micro-benchmark suite covering the four hot paths
real callers exercise: constructor cost, ``URLPattern.test()`` throughput,
``URLPattern.exec()`` throughput, and the ``yarl.URL`` input fast path.
Layout:
benchmarks/conftest.py shared fixtures + a representative
cross-section of pattern shapes
(literal, named-group, regex-constrained,
wildcard-tail, multi-component dict)
benchmarks/bench_construction.py 4 + 3 = 7 construction benchmarks
benchmarks/bench_test.py 6 test() benchmarks
benchmarks/bench_exec.py 6 exec() benchmarks
benchmarks/bench_yarl_fast_path.py
4 string-vs-yarl.URL pairs
23 benchmarks in total. The suite is *not* picked up by the default
``pytest`` invocation (``testpaths = ["tests"]``); invoke explicitly:
just bench # run, print summary
just bench-save # run, save baseline keyed on HEAD SHA
The harness is pinned via the ``bench`` dependency-group (PEP 735), not a
published extra — pytest-benchmark is contributor / maintainer tooling.
The suite is deliberately self-comparative only: cross-library URLPattern
comparisons are a different exercise with their own methodological
pitfalls and are out of scope here.
Part of v0.2.0 roadmap.
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
benchmarks/covering the four hot paths: constructor cost,URLPattern.test(),URLPattern.exec(), and theyarl.URLinput fast path.Why a separate suite (not in
tests/)The benchmark suite lives outside
tests/so the defaultpytestinvocation does not pick it up (testpaths = ["tests"]). It is contributor / maintainer tooling — not something end users need to run.Layout
Pattern shapes cover the spectrum: literal-only, named-group, regex-constrained, wildcard-tail, and the MDN kitchen-sink multi-component dict.
How to run
The harness is gated behind a PEP 735
[dependency-groups]entry (bench), pinningpytest-benchmark>=5.1.0. Not exposed as a published extra.Test plan
just bench— all 23 benchmarks pass (locally verified)uv run pytest -q— 580 passed, 19 skipped (no regression — defaultpytestdoes not touchbenchmarks/)just lint— all tools green (ruff, mypy, pyright, ty, semgrep, etc.)Scope notes
Deliberately self-comparative only. Cross-library URLPattern benchmarks have their own methodological pitfalls (different parser, different regex engine, different I/O) and are out of scope for this PR.
Part of the v0.2.0 roadmap.