Pages: 1 [2]   Go Down
Author Topic: serial.print or serial.write?  (Read 23964 times)
0 Members and 2 Guests are viewing this topic.
Seattle, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 248
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

.andy

Global Moderator
The Netherlands
Offline Offline
Sr. Member
*****
Karma: 1
Posts: 287
don't panic...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Jeroen
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, USA
Offline Offline
Full Member
***
Karma: 0
Posts: 248
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

.andy

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,  smiley-wink 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
« Last Edit: November 04, 2009, 10:55:24 pm by retrolefty » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 206
Posts: 12850
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: November 05, 2009, 02:45:03 pm by bcook » Logged

Global Moderator
The Netherlands
Offline Offline
Sr. Member
*****
Karma: 1
Posts: 287
don't panic...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: 1 [2]   Go Up
Jump to: