Using Serial.print for debugging significantly slows down a sketch. Once I have a sketch working as I want (for now), I may use find and replace and change Serial.print to //Serial.print and this speeds everything up.
Do i need to do this or simply comment out the Serial.begin?
If I do just comment out the Serial.begin, will the Serial.print commands still use processing power?
Should I comment out both Serial.begin and Serial.print commands for optimal performance?
I've now run the experiment and got part of my answer.
I am trying to see how long a single 3.2v lifepo battery will last on a Lolin 32 lite. To save battery, i put the esp32 into deep sleep every 12 seconds after writing sensor values to an array. After 120 seconds the sensor values are averaged and saved to SPIFFS, and it goes to sleep again.
By commenting out the Serial.begin and Serial.print lines, it saves 30% of the time it is awake.
You have to replace all of your Serial.print(foo); debug statements with PRINTS(foo)' and etc.
I like
static const DEBUG = 0;
#define debugPrint(...) do (if (DEBUG) Serial.print(__VA_ARGS__) while (0)
#define debugPrintln(...) do (if (DEBUG) Serial.println(__VA_ARGS__) while (0)
This way, if you make DEBUG a static const as above the compiler optimization will give you either a simple Serial.print, or nothing, but you also have the option of making DEBUG a variable that you can change at runtime.
logical: You have defined some makros but you are not using them.
You still print with Serial.print.
You should adopt your Serial.print to one of your makros.
by the way ... don't use so short makros ... everytime you would write PL in your code it will be replaced by the makro ... use something like debugPrint ... and only use that for your debug messages.
When you define the macros, you are basically telling IDE to replace what ever chatacters that you have defined with the ones that you specify. Is this correct?
So if I use #define PRINTS(s) { Serial.print(F(s)); } and #define PRINTS(s), I would need to find and replace my 'Serial.print' commands and replace them with 'PRINTS'?
I misunderstood, I thought that these macros were instructing IDE to ignore the Serial.print command.