Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

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

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Location
    Murfreesboro, Tn, USA
    Posts
    8

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

    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);......Se rialPrint(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();

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,592
    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.

  3. #3
    Junior Member
    Join Date
    Aug 2017
    Location
    Murfreesboro, Tn, USA
    Posts
    8
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •