Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASCWriter speed improvement #1856

Merged
merged 6 commits into from
Sep 13, 2024
Merged

ASCWriter speed improvement #1856

merged 6 commits into from
Sep 13, 2024

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.

👍

test/logformats_test.py Outdated Show resolved Hide resolved
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.
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants