Noob questions; (X) vs. (y) for optimizing speed/efficiency of program.

Status
Not open for further replies.
Disclaimer: I am quite a novice for programming. no formal education in CS or EE, etc. Just a lot of web searching.

IF you had to choose a specific method, which one and why?
Sprintf (Multiple objects formatted output) vs. SerialPrint(object1);SerialPrint(object2);......SerialPrint(object10);

Sprintf code below:
Code:
  char buf5[] = "";  uint8_t i2 = 0;
  for ( uint8_t i = 0; i < msg.len; i++ ) {
      i2+=sprintf(buf5+i2, " %02x",msg.buf[i]);    
  }
Serial.println(buf5);

Serial print code below:
Code:
   for ( uint8_t i = 0; i < msg.len; i++ ) {
    if  (msg.buf[i] <16) {
      Serial.print("0");
    }
    Serial.print(msg.buf[i], HEX); Serial.print(" ");
  }
 Serial.println();
 
It really depends on the platform for which you develop. It seems that in certain compiler versions and/or certain h/w platforms, Sprintf is poorly (slow and memory consuming) or not at all implemented. On others, it works rather well.
The general tendency on embedded platforms seems rather to not use Sprintf in order to save on memory and execution speed, while when writing programs for desktop computers, it’s less a problem.
 
Compiler is arduino, h/w : teensy 3.6.

I might go back to the Serial.print option if it seems to work better across the board.

The faster, the better, and
The less dependencies, the better.
 
Status
Not open for further replies.
Back
Top