Skip to content

Commit

Permalink
fix parser perf test (commaai#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh authored and eFiniLan committed Aug 31, 2023
1 parent 7cdace6 commit e03dd01
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions can/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,33 @@ class TestParser(unittest.TestCase):
def _benchmark(self, signals, checks, thresholds, n):
parser = CANParser('toyota_new_mc_pt_generated', signals, checks, 0, False)
packer = CANPacker('toyota_new_mc_pt_generated')

can_msgs = []
for i in range(50000):
values = {"ACC_CONTROL": {"ACC_TYPE": 1, "ALLOW_LONG_PRESS": 3}}
msgs = [packer.make_can_msg(k, 0, v) for k, v in values.items()]
bts = can_list_to_can_capnp(msgs, logMonoTime=int(0.01 * i * 1e9))
can_msgs.append(bts)

if n > 1:
strings = []
for i in range(0, len(can_msgs), n):
strings.append(can_msgs[i:i + n])
t1 = time.process_time_ns()
for m in strings:
parser.update_strings(m)
t2 = time.process_time_ns()
else:
t1 = time.process_time_ns()
for m in can_msgs:
parser.update_string(m)
t2 = time.process_time_ns()
ets = []
for _ in range(25):
if n > 1:
strings = []
for i in range(0, len(can_msgs), n):
strings.append(can_msgs[i:i + n])
t1 = time.process_time_ns()
for m in strings:
parser.update_strings(m)
t2 = time.process_time_ns()
else:
t1 = time.process_time_ns()
for m in can_msgs:
parser.update_string(m)
t2 = time.process_time_ns()

ets.append(t2 - t1)

et = t2 - t1
et = sum(ets) / len(ets)
avg_nanos = et / len(can_msgs)
method = 'update_strings' if n > 1 else 'update_string'
print('%s: [%s] %.1fms to parse %s, avg: %dns' % (self._testMethodName, method, et/1e6, len(can_msgs), avg_nanos))
Expand Down

0 comments on commit e03dd01

Please sign in to comment.