chore: add socket unmarshall benchmark (#428)
* chore: add socket unmarshall benchmark * chore: bench multiple messages
This commit is contained in:
parent
bfc8151005
commit
1802f35ce9
@ -1,4 +1,5 @@
|
||||
import io
|
||||
import socket
|
||||
|
||||
from pytest_codspeed import BenchmarkFixture
|
||||
|
||||
@ -25,8 +26,7 @@ def test_unmarshall_bluez_rssi_message(benchmark: BenchmarkFixture) -> None:
|
||||
unmarshaller.unmarshall()
|
||||
|
||||
|
||||
def test_unmarshall_bluez_properties_message(benchmark: BenchmarkFixture) -> None:
|
||||
bluez_properties_message = (
|
||||
bluez_properties_message = (
|
||||
b"l\4\1\0014\0\0\0\16Q\16\0\225\0\0\0\1\1o\0%\0\0\0/org/bluez/hci2/dev_08_3A_F2_1E_28_89\0\0\0\2\1s\0\37\0\0\0"
|
||||
b"org.freedesktop.DBus.Properties\0\3\1s\0\21\0\0\0PropertiesChanged\0\0\0\0\0\0\0\10\1g\0\10sa{sv}as\0\0\0\7\1"
|
||||
b"s\0\4\0\0\0:1.5\0\0\0\0\21\0\0\0org.bluez.Device1\0\0\0\16\0\0\0\0\0\0\0\4\0\0\0RSSI\0\1n\0\242\377\0\0\0\0\0\0"
|
||||
@ -55,7 +55,10 @@ def test_unmarshall_bluez_properties_message(benchmark: BenchmarkFixture) -> Non
|
||||
b"4\0\0\0\26Q\16\0\225\0\0\0\1\1o\0%\0\0\0/org/bluez/hci3/dev_F8_04_2E_E1_9F_19\0\0\0\2\1s\0\37\0\0\0org.freedesktop.D"
|
||||
b"Bus.Properties\0\3\1s\0\21\0\0\0PropertiesChanged\0\0\0\0\0\0\0\10\1g\0\10sa{sv}as\0\0\0\7\1s\0\4\0\0\0:1.5\0\0\0\0"
|
||||
b"\21\0\0\0org.bluez.Device1\0\0\0\16\0\0\0\0\0\0\0\4\0\0\0RSSI\0\1n\0\306\377\0\0\0\0\0\0"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_unmarshall_bluez_properties_message(benchmark: BenchmarkFixture) -> None:
|
||||
stream = io.BytesIO(bluez_properties_message)
|
||||
|
||||
unmarshaller = Unmarshaller(stream)
|
||||
@ -64,3 +67,35 @@ def test_unmarshall_bluez_properties_message(benchmark: BenchmarkFixture) -> Non
|
||||
def unmarshall_bluez_properties_message():
|
||||
stream.seek(0)
|
||||
unmarshaller.unmarshall()
|
||||
|
||||
|
||||
def test_unmarshall_multiple_bluez_properties_message(
|
||||
benchmark: BenchmarkFixture,
|
||||
) -> None:
|
||||
stream = io.BytesIO(bluez_properties_message)
|
||||
|
||||
unmarshaller = Unmarshaller(stream)
|
||||
|
||||
@benchmark
|
||||
def unmarshall_bluez_properties_message():
|
||||
stream.seek(0)
|
||||
for _ in range(9):
|
||||
unmarshaller.unmarshall()
|
||||
|
||||
|
||||
def test_unmarshall_multiple_bluez_properties_message_socket(
|
||||
benchmark: BenchmarkFixture,
|
||||
) -> None:
|
||||
sock1, sock2 = socket.socketpair()
|
||||
sock1.setblocking(False)
|
||||
sock2.setblocking(False)
|
||||
unmarshaller = Unmarshaller(None, sock1, False)
|
||||
|
||||
@benchmark
|
||||
def unmarshall_bluez_properties_message():
|
||||
sock2.send(bluez_properties_message)
|
||||
for _ in range(9):
|
||||
unmarshaller.unmarshall()
|
||||
|
||||
sock1.close()
|
||||
sock2.close()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user