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

[question] Why is readBytes considered slow? #2

Open
hazkaz opened this issue Feb 9, 2020 · 2 comments
Open

[question] Why is readBytes considered slow? #2

hazkaz opened this issue Feb 9, 2020 · 2 comments
Labels
question Further information is requested

Comments

@hazkaz
Copy link

hazkaz commented Feb 9, 2020

Hi @araffin , I came across your library and medium article and found it helpful in writing my own binary protocol for arduino. I was wondering why you considered that readBytes is slow compared to checking if serial.available()>size and then using read().

// NOTE : Serial.readBytes is SLOW

@hazkaz hazkaz changed the title Why is readBytes considered slow? [question] Why is readBytes considered slow? Feb 9, 2020
@araffin araffin added the question Further information is requested label Feb 9, 2020
@araffin
Copy link
Owner

araffin commented Feb 9, 2020

Hello,

Good question, I think this came from test a colleague did a while ago (already 5 years from now...)

But maybe it has changed or the test is not valid anymore. Feel free to replace that with the readBytes, I would be happy to have a feeback/proper comparison ;).

@hazkaz
Copy link
Author

hazkaz commented Feb 11, 2020

Hi,
I looked up the code for upto 2012 and based on what I saw, the code for readBytes and timedRead are the same. What might however cause different behaviour is that readBytes calls timedRead n times for n bytes. Each timedRead makes a call to millis (which could be making the difference here).

Your code however waits for the all the bytes to be available in the serial buffer before reading all of them at once.

I haven't made any measurements on a DSO and can't verify this however. I don't even know if readBytes is infact slower, let alone how much slower per byte(microseconds, milliseconds etc). Let me know if you find out more.

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

No branches or pull requests

2 participants