Go Down

Topic: serial.print or serial.write? (Read 28197 times) previous topic - next topic

ahdavidson

I agree about the readability. Since your data is not text, Serial.write seems to makes more logical sense, while Serial.print implies human-readable data (to me).

I'm not an expert but my understanding is that the extra overhead of Seril.print is probably a few instructions and a function call. Even at high baud rates, I'm guessing that would be just roundoff errors in performance.

But I'm really just speculating and waiting for a more knowledgeable geek to chime in here on this increasingly prolonged (by me) discussion of marginal utility.

;D
.andy

Yot

Prolonged discussions of marginal utility. What a luxury isn't it?  :)

Jeroen

retrolefty

Quote
Prolonged discussions of marginal utility. What a luxury isn't it?


Maybe, but it's not unlike the use of Arduino pin numbering Vs direct port I/O access. The first is more readable and portable across the various AVR chips but it does carry a speed penalty compared to the second method. So it's nice to be educated about both methods, their trade-offs so that one's application can point to the best method needed.

Lefty

ahdavidson

Lefty, you're good at performance calculations. Any estimates on the Serial.print vs Serial.write runtime overhead? Of academic interest and pure curiosity, at this point...
.andy

retrolefty

#19
Nov 05, 2009, 04:53 am Last Edit: Nov 05, 2009, 04:55 am by retrolefty Reason: 1
Quote
Lefty, you're good at performance calculations.


Nah, I'm more of a electronics hardware guy, still learning C/C++ and the class stuff really kind of confuses me a little, no more like a lot,  ;) Someone more qualified would have to tackle your question.

I do know that the speed difference (as seen on a scope) between using Arduino pin statements Vs direct acess I/O was pretty significant. Again it's not important for all applications but where you really need to flip the bits in min time it's a good tool to have around.

Lefty

Coding Badly

#20
Nov 05, 2009, 07:09 am Last Edit: Nov 05, 2009, 08:45 pm by bcook Reason: 1
Comments from the Arduino 15 libraries...

Quote
Any estimates on the Serial.print vs Serial.write runtime overhead? Of academic interest and pure curiosity, at this point...

Relative to the others, Serial.write has zero overhead.  All the Serial.print methods eventually call Serial.write.

print( /*unsigned*/ int) is more expensive than print( /*unsigned*/ long) for the simple reason that the int-print methods cast the argument to (unsigned) long and call print( /*unsigned*/ long).

The unsigned-print methods are slightly faster than the signed-print methods.

Without a doubt, printing a floating-point number is the most expensive method.

The one glaring omission is the lack of an optimized print for integers to hexidecimal.

Yot

Quote

Maybe, but it's not unlike the use of Arduino pin numbering Vs direct port I/O access. The first is more readable and portable across the various AVR chips but it does carry a speed penalty compared to the second method. So it's nice to be educated about both methods, their trade-offs so that one's application can point to the best method needed.

Lefty


Totally true. In my case speed/overhead wasn't the issue that's why is replied with the "Prolonged discussions of marginal utility. What a luxury isn't it?"

All feel free to discuss the overhead in here but wouldn't the subject be worthy of it's own thread for clarity and easy of finding it through forum search?

Jeroen

Go Up