| 1 |
|
| 2 |
"""Benchmarks for the 16/32/128-bit Service UUID list parse loops. |
| 3 |
|
| 4 |
These exercise the multi-entry UUID list branches of |
| 5 |
``_uncached_parse_advertisement_bytes`` so the per-iteration hoist of the |
| 6 |
length bounds check (``safe_end = start + ((end - start) & ~(N-1))``) has |
| 7 |
something to measure against. The wider real-world dataset in |
| 8 |
``test_parse_gap_bytes`` is dominated by single-UUID payloads and 16-byte |
| 9 |
slice allocations, both of which mask changes in the loop body. |
| 10 |
""" |
| 11 |
|
| 12 |
from pytest_codspeed import BenchmarkFixture |
| 13 |
|
| 14 |
from bluetooth_data_tools.gap import _uncached_parse_advertisement_bytes |
| 15 |
|
| 16 |
_FLAGS = b"\x02\x01\x06" |
| 17 |
_LOCAL_NAME = b"\x07\tDevice" |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
_UUIDS_16 = b"\x0f\x03\x12\x18\x0a\x18\x0d\x18\x0f\x18\x05\x18\x09\x18\x02\x18" |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
_UUIDS_32 = b"\x0d\x05\x12\x18\x00\x00\x0a\x18\x00\x00\x0d\x18\x00\x00" |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
_UUIDS_128 = b"\x21\x07" + bytes(range(16)) + bytes(range(16, 32)) |
| 31 |
|
| 32 |
ADV_16BIT_LIST = _FLAGS + _UUIDS_16 + _LOCAL_NAME |
| 33 |
ADV_32BIT_LIST = _FLAGS + _UUIDS_32 + _LOCAL_NAME |
| 34 |
ADV_128BIT_LIST = _FLAGS + _UUIDS_128 + _LOCAL_NAME |
| 35 |
ADV_MIXED_LIST = _FLAGS + _UUIDS_16 + _UUIDS_32 + _UUIDS_128 + _LOCAL_NAME |
| 36 |
|
| 37 |
|
| 38 |
def test_parse_advertisement_16bit_uuid_list(benchmark: BenchmarkFixture) -> None: |
| 39 |
benchmark(lambda: _uncached_parse_advertisement_bytes(ADV_16BIT_LIST)) |
| 40 |
|
| 41 |
|
| 42 |
def test_parse_advertisement_32bit_uuid_list(benchmark: BenchmarkFixture) -> None: |
| 43 |
benchmark(lambda: _uncached_parse_advertisement_bytes(ADV_32BIT_LIST)) |
| 44 |
|
| 45 |
|
| 46 |
def test_parse_advertisement_128bit_uuid_list(benchmark: BenchmarkFixture) -> None: |
| 47 |
benchmark(lambda: _uncached_parse_advertisement_bytes(ADV_128BIT_LIST)) |
| 48 |
|
| 49 |
|
| 50 |
def test_parse_advertisement_mixed_uuid_lists(benchmark: BenchmarkFixture) -> None: |
| 51 |
benchmark(lambda: _uncached_parse_advertisement_bytes(ADV_MIXED_LIST)) |