Skip to content

Conversation

pierreluctg
Copy link
Collaborator

@pierreluctg pierreluctg commented Sep 12, 2024

Changed how the message data is converted to string.

Main

$ python -m timeit -s "import can; writer=can.ASCWriter('test.asc')" "writer(can.Message(data=range(64)))" 20000 loops, best of 5: 10.8 usec per loop 

This PR

$ python -m timeit -s "import can; writer=can.ASCWriter('test.asc')" "writer(can.Message(data=range(64)))" 50000 loops, best of 5: 3.97 usec per loop 
@pierreluctg pierreluctg added enhancement file-io about reading & writing to files labels Sep 12, 2024
@pierreluctg pierreluctg marked this pull request as ready for review September 12, 2024 15:57
Copy link
Collaborator

@felixdivo felixdivo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

pierreluctg and others added 6 commits September 13, 2024 10:28
Changed how the message data is converted to string. This results in and 100% speed improvement. On my PC, before the change, logging 10000 messages was taking ~16 seconds and this change drop it to ~8 seconds. With this change, the ASCWriter is still one of the slowest writer we have in Python-can.
Co-authored-by: Felix Divo <4403130+felixdivo@users.noreply.github.com>
@pierreluctg pierreluctg merged commit d4f3954 into main Sep 13, 2024
64 checks passed
@pierreluctg pierreluctg deleted the ASCWriter-speed branch September 13, 2024 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement file-io about reading & writing to files

3 participants