mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2024-12-22 16:48:04 +01:00
Add benchmark for processing raw ble messages (#624)
This commit is contained in:
parent
ef9f9bf136
commit
92eaf62f8b
@ -4,6 +4,7 @@ source = aioesphomeapi
|
|||||||
omit =
|
omit =
|
||||||
aioesphomeapi/api_options_pb2.py
|
aioesphomeapi/api_options_pb2.py
|
||||||
aioesphomeapi/api_pb2.py
|
aioesphomeapi/api_pb2.py
|
||||||
|
bench/*.py
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
# Regexes for lines to exclude from consideration
|
# Regexes for lines to exclude from consideration
|
||||||
|
54
bench/raw_ble_plain_text.py
Normal file
54
bench/raw_ble_plain_text.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import io
|
||||||
|
import timeit
|
||||||
|
|
||||||
|
from aioesphomeapi._frame_helper import APIPlaintextFrameHelper
|
||||||
|
from aioesphomeapi._frame_helper.plain_text import _cached_varuint_to_bytes
|
||||||
|
from aioesphomeapi.api_pb2 import (
|
||||||
|
BluetoothLERawAdvertisement,
|
||||||
|
BluetoothLERawAdvertisementsResponse,
|
||||||
|
)
|
||||||
|
|
||||||
|
# cythonize -X language_level=3 -a -i aioesphomeapi/_frame_helper/plain_text.py
|
||||||
|
# cythonize -X language_level=3 -a -i aioesphomeapi/_frame_helper/base.py
|
||||||
|
|
||||||
|
adv = BluetoothLERawAdvertisementsResponse()
|
||||||
|
fake_adv = BluetoothLERawAdvertisement(
|
||||||
|
address=1,
|
||||||
|
rssi=-86,
|
||||||
|
address_type=2,
|
||||||
|
data=(
|
||||||
|
b"6c04010134000000e25389019500000001016f00250000002f6f72672f626c75"
|
||||||
|
b"657a2f686369302f64656c04010134000000e25389019500000001016f002500"
|
||||||
|
b"00002f6f72672f626c75657a2f686369302f6465"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
for i in range(5):
|
||||||
|
adv.advertisements.append(fake_adv)
|
||||||
|
|
||||||
|
type_ = 93
|
||||||
|
data = adv.SerializeToString()
|
||||||
|
data = (
|
||||||
|
b"\0" + _cached_varuint_to_bytes(len(data)) + _cached_varuint_to_bytes(type_) + data
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _packet(type_: int, data: bytes):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _on_error(exc: Exception):
|
||||||
|
raise exc
|
||||||
|
|
||||||
|
|
||||||
|
helper = APIPlaintextFrameHelper(
|
||||||
|
on_pkt=_packet, on_error=_on_error, client_info="my client", log_name="test"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def process_incoming_msg():
|
||||||
|
helper.data_received(data)
|
||||||
|
|
||||||
|
|
||||||
|
count = 3000000
|
||||||
|
time = timeit.Timer(process_incoming_msg).timeit(count)
|
||||||
|
print(f"Processed {count} bluetooth messages took {time} seconds")
|
Loading…
Reference in New Issue
Block a user