mirror of https://github.com/commaai/panda.git
benchmarking script
This commit is contained in:
parent
5847d7dbc0
commit
e1e9bd048d
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python3
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
|
||||
from panda import Panda, PandaDFU
|
||||
from panda.tests.hitl.helpers import get_random_can_messages
|
||||
|
||||
|
||||
@contextmanager
|
||||
def print_time(desc):
|
||||
start = time.perf_counter()
|
||||
yield
|
||||
end = time.perf_counter()
|
||||
print(f"{end - start:.2f}s - {desc}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with print_time("Panda()"):
|
||||
p = Panda()
|
||||
|
||||
with print_time("PandaDFU.list()"):
|
||||
PandaDFU.list()
|
||||
|
||||
fxn = [
|
||||
'reset',
|
||||
'reconnect',
|
||||
'up_to_date',
|
||||
'health',
|
||||
#'flash',
|
||||
]
|
||||
for f in fxn:
|
||||
with print_time(f"Panda.{f}()"):
|
||||
getattr(p, f)()
|
||||
|
||||
p.set_can_loopback(True)
|
||||
|
||||
for n in range(6):
|
||||
msgs = get_random_can_messages(int(10**n))
|
||||
with print_time(f"Panda.can_send_many() - {len(msgs)} msgs"):
|
||||
p.can_send_many(msgs)
|
||||
|
||||
with print_time("Panda.can_recv()"):
|
||||
m = p.can_recv()
|
|
@ -2,6 +2,16 @@ import time
|
|||
import random
|
||||
|
||||
|
||||
def get_random_can_messages(n):
|
||||
m = []
|
||||
for _ in range(n):
|
||||
bus = random.randrange(3)
|
||||
addr = random.randrange(1 << 29)
|
||||
dat = bytes([random.getrandbits(8) for _ in range(random.randrange(1, 9))])
|
||||
m.append([addr, None, dat, bus])
|
||||
return m
|
||||
|
||||
|
||||
def time_many_sends(p, bus, p_recv=None, msg_count=100, two_pandas=False):
|
||||
if p_recv is None:
|
||||
p_recv = p
|
||||
|
|
Loading…
Reference in New Issue