<edit>: BTW - is this testing as suggested? There is a huge jump in recorded counts between LTO and non-LTO and from initial results above of under a few Million to these of 25 and 34 Million and down to 12 Million with no LTO????
Hopefully not OT, or posting to myself...:: the compiler update seems good and LTO shows improvement - just have to be careful to test what is intended - seeing something odd may be the test itself::
Final answer to report loop() counts -
treat the count like a running timer that wraps properly on uint32_t. With {setup above} results in counts near 34,265,240 at 240 MHz and 25,695,089 at 180 MHz compiled FASTER with LTO:
Code:
volatile uint32_t count = 0;
static uint32_t Lastcount = 0;
void one_s_task() {
Serial.print(count - Lastcount);
Serial.print("=# @");
Serial.println(millis());
Lastcount = count;
}
void loop() {
count++;
}
With default Arduino PJRC yield drops the 180 MHz count to 2,644,868. But this is basically on an empty loop() - even indexing an array for counting drops the count 50% as below. Further below compile results show that the LTO option is needed to see this extreme high count.
Edit on prior post sharing the USB print time - and resolves the interrupted loop() count++, but then it doesn't exemplify the problem any more gives 21,805,536 at 240 MHz that shows the effect of array indexing overhead to get
loop(){Clist[ii]++;}. This shows a second way to count and may be an isr() safe way to swap buffers?:
Code:
uint32_t Clist[2] = {0,0};
void one_s_task() {
ii^=1;
Serial.print(Clist[ii]);
Serial.print("=# @");
Serial.println(millis());
Clist[ii] = 0;
}
This shows some alternate compiles - the LTO is key here??:
setup() ----- F_CPU=240000000 // FASTER with LTO
34265346=# @2400
setup() ----- F_CPU=240000000 // FASTEST with LTO :: Sketch uses 10940 bytes
34265275=# @2400
setup() ----- F_CPU=240000000 // FASTEST with no LTO :: Sketch uses 13076 bytes
12624948=# @2400
setup() ----- F_CPU=240000000 // FAST with no LTO
12624954=# @2400
setup() ----- F_CPU=240000000 // SMALLEST with no LTO
14109973=# @2400
setup() ----- F_CPU=240000000 // SMALLEST with LTO :: Sketch uses 6828 bytes
34264891=# @2400
Doing FASTEST and
no LTO using
default yield() gives this::
setup() ----- F_CPU=240000000
1689107=# @2400
Last note - I set the IntervalTimer to 10 seconds and got this - count at 240 MHz range is ~400 per 10 secs and ~9,000 when at 180 MHz:
setup() ----- F_CPU=240000000 // FAST with LTO :: Sketch uses 8064 bytes and void yield(void) { }
342,651,037=# @11400
setup() ----- F_CPU=180000000 // FAST with LTO :: Sketch uses 8064 bytes and void yield(void) { }
256,948,736=# @11400
Final sketch with both methods:
View attachment IntervalCounterISR.ino