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

Benchmarks #1

Open
danielhrisca opened this issue Dec 31, 2022 · 1 comment
Open

Benchmarks #1

danielhrisca opened this issue Dec 31, 2022 · 1 comment

Comments

@danielhrisca
Copy link

Hello,

Do you have some comparison numbers against the Python-can default bus?

@zariiii9003
Copy link
Owner

I made a little script back then. I'm not sure how reliable these numbers are, but here you are:

import sys
import timeit


setup_0 = r"""
import random

from can import Message, Bus

FD = True
LEN = 64 if FD else 8
MSG = Message(
    arbitration_id=100, 
    is_fd=FD, 
    data=[random.randint(0, 255) for _ in range(LEN)], 
    dlc=LEN,
)
"""

setup_1 = setup_0 + r"""
bus = Bus(
    interface="vector",
    serial=100,
    channel=1,
    fd=FD,
    receive_own_messages=True
)
bus.send(MSG)
"""

setup_2 = setup_0 + r"""
bus = Bus(
    interface="cvector",
    serial=100,
    channel=1,
    fd=FD,
    receive_own_messages=True
)
bus.send(MSG)
"""

send_and_receive = r"""
bus.send(MSG)
bus.recv()
"""

send_only = r"""
bus.send(MSG)
"""


reps = 3
loops = 10000

print(sys.version)
python_can = min(timeit.Timer(send_and_receive, setup=setup_1).repeat(reps, loops))
cython_can = min(timeit.Timer(send_and_receive, setup=setup_2).repeat(reps, loops))
print(f"send & receive: {python_can=}s, {cython_can}s, {python_can / cython_can:.2f}")

python_can = min(timeit.Timer(send_only, setup=setup_1).repeat(reps, loops))
cython_can = min(timeit.Timer(send_only, setup=setup_2).repeat(reps, loops))
print(f"send only: {python_can=}s, {cython_can}s, {python_can / cython_can:.2f}")

Which prints

3.10.9 (tags/v3.10.9:1dd9be6, Dec  6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)]
send & receive: python_can=0.2280426000006628s, 0.03325200000017503s, 6.86
send only: python_can=0.12258299999939481s, 0.021391100000073493s, 5.73

So roughly factor 6 with the virtual bus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants