Skip to content

Commit

Permalink
feat: add unpack variants benchmark (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 9, 2022
1 parent 33374ef commit eb966fd
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions bench/unpack_variants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import timeit

from dbus_fast import Variant, unpack_variants

message = {
"/org/bluez/hci0": {
"org.bluez.Adapter1": {
"Address": Variant("s", "00:E0:4C:2A:25:63"),
"AddressType": Variant("s", "public"),
"Alias": Variant("s", "BlueZ 5.63"),
"Class": Variant("u", 2883584),
"Discoverable": Variant("b", False),
"DiscoverableTimeout": Variant("u", 180),
"Discovering": Variant("b", True),
"Modalias": Variant("s", "usb:v1D6Bp0246d053F"),
"Name": Variant("s", "BlueZ 5.63"),
"Pairable": Variant("b", False),
"PairableTimeout": Variant("u", 0),
"Powered": Variant("b", True),
"Roles": Variant("as", ["central", "peripheral"]),
"UUIDs": Variant(
"as",
[
"0000110e-0000-1000-8000-00805f9b34fb",
"0000110a-0000-1000-8000-00805f9b34fb",
"00001200-0000-1000-8000-00805f9b34fb",
"0000110b-0000-1000-8000-00805f9b34fb",
"00001108-0000-1000-8000-00805f9b34fb",
"0000110c-0000-1000-8000-00805f9b34fb",
"00001800-0000-1000-8000-00805f9b34fb",
"00001801-0000-1000-8000-00805f9b34fb",
"0000180a-0000-1000-8000-00805f9b34fb",
"00001112-0000-1000-8000-00805f9b34fb",
],
),
},
"org.bluez.GattManager1": {},
"org.bluez.LEAdvertisingManager1": {
"ActiveInstances": Variant("y", 0),
"SupportedIncludes": Variant(
"as", ["tx-power", "appearance", "local-name"]
),
"SupportedInstances": Variant("y", 4),
"SupportedSecondaryChannels": Variant("as", ["1M", "2M", "Coded"]),
},
"org.bluez.Media1": {},
"org.bluez.NetworkServer1": {},
"org.freedesktop.DBus.Introspectable": {},
"org.freedesktop.DBus.Properties": {},
},
}


def unpack_managed_objects():
unpack_variants(message)


count = 3000000
time = timeit.Timer(unpack_managed_objects).timeit(count)
print(f"Unpacked {count} get managed objects messages took {time} seconds")

0 comments on commit eb966fd

Please sign in to comment.