2023-11-09 16:31:13 +01:00
|
|
|
import timeit
|
|
|
|
|
2023-11-21 11:53:04 +01:00
|
|
|
from aioesphomeapi import APIConnection
|
2023-11-09 16:31:13 +01:00
|
|
|
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
|
2023-11-21 11:53:04 +01:00
|
|
|
# cythonize -X language_level=3 -a -i aioesphomeapi/connection.py
|
2023-11-09 16:31:13 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-11-21 11:53:04 +01:00
|
|
|
class MockConnection(APIConnection):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
pass
|
2023-11-09 16:31:13 +01:00
|
|
|
|
2023-11-21 11:53:04 +01:00
|
|
|
def process_packet(self, type_: int, data: bytes):
|
|
|
|
pass
|
2023-11-09 16:31:13 +01:00
|
|
|
|
2023-11-21 11:53:04 +01:00
|
|
|
def report_fatal_error(self, exc: Exception):
|
|
|
|
raise exc
|
2023-11-09 16:31:13 +01:00
|
|
|
|
|
|
|
|
2023-11-21 11:53:04 +01:00
|
|
|
connection = MockConnection()
|
|
|
|
|
2023-11-09 16:31:13 +01:00
|
|
|
helper = APIPlaintextFrameHelper(
|
2023-11-21 11:53:04 +01:00
|
|
|
connection=connection, client_info="my client", log_name="test"
|
2023-11-09 16:31:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
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")
|