I'm working in a small project, which consists in an IoT sensor network, which uploads the readings to a Google Spreadsheets file, my doubt, and the purpose of this post is, as you know, any code has println() commands to check it's behavior during the tests and prototypes... So I'm planning to just comment these afore said commands to save resources during the actual executions of my code. My question is: commenting the println() will actually optimize my code performance? Or it won't make such difference?
I wouldn't like to delete those commands in order to easily understand my code structure in the future. And don't loose too much time improving it in the future if the chance is set.
you could use macros for the debug comments. Once they are not needed, just change the debug flag and recompile, all the calls are gone (and you get some memory back)
#define DEBUG 1 // SET TO 0 OUT TO REMOVE TRACES
#if DEBUG
#define D_SerialBegin(...) Serial.begin(__VA_ARGS__);
#define D_print(...) Serial.print(__VA_ARGS__)
#define D_write(...) Serial.print(__VA_ARGS__)
#define D_println(...) Serial.println(__VA_ARGS__)
#else
#define D_SerialBegin(bauds)
#define D_print(...)
#define D_write(...)
#define D_println(...)
#endif
The risk with Serial printing is that it will block when the output buffer is full. The lower the baud rate and the more stuff you print, the more likely that becomes.
If you're not blocking, I wouldn't expect much of a performance difference, especially if you're waiting for responses from a cloud server. Note though, that you should test thoroughly once you comment the prints out because in some cases, the time taken to print was masking some other timing issue.
Personally, I leave the prints alone until I can prove to myself that they're causing a problem.