test: add benchmarks for ipaddress object creation and hashing by bluetoothbot · Pull Request #1773 · python-zeroconf/python-zeroconf
What
Add CodSpeed benchmarks for ZeroconfIPv4Address / ZeroconfIPv6Address construction and hashing.
Why
get_ip_address_object_from_record builds one of these objects per A/AAAA record on a cache miss, and the objects are hashed when stored in sets/dicts. There is currently no benchmark guarding the construction or hash cost of this hot path, so regressions (or improvements) go unmeasured.
This establishes the baseline before a follow-up that reworks how the per-instance hash is cached.
How
Four benchmarks under tests/benchmarks/test_ipaddress.py:
- construct 1000 distinct IPv4 / IPv6 address objects (
__init__cost) - hash a warm IPv4 / IPv6 address 1000× (memoized-hash cost)
Testing
SKIP_CYTHON=1 poetry run pytest tests/benchmarks/test_ipaddress.py -v — 4 passed. ruff + ruff-format clean.