defragster
Senior Member+
IMPROVED:: LC much slower than T3.1 : MICROS updated
<edit>: Confirming that 1.24b3 compiles LC to run micros FASTER and well.
<edit>:
LC is unexpectedly slower than a T3.1 for seemingly simple counting loop? Is this from using elapsedMicros [unsigned long us;] comparison? [Putting a (uint16_t) cast on it doesn't help]
IDE_1.6.3 w/TLoader_1.24.b2
Full Code below gives:
> inWhile==78 for LC OPTIMIZED 48MHz
> inWhile==77 for LC 48MHz
> inWhile==44 for LC OPTIMIZED 24MHz
> inWhile==846 for T3.1 OPTIMIZED 96MHz
> inWhile==422 for T3.1 OPTIMIZED 48MHz
PS: I should recode this with METRO to compare.
<edit>: Confirming that 1.24b3 compiles LC to run micros FASTER and well.
<edit>:
Serial.print() and micros() have become highly optimized as a result of this conversation. Until a couple days ago, Teensy-LC ran that test in 228 microseconds. Now it takes only 62 microseconds! A similar speedup was made in micro().
{ ... }
Even before the optimization, Teensy-LC was over 6X faster than regular 8 bit Arduino boards ... Now with the optimization, it's 22X faster than regular AVR boards.
LC is unexpectedly slower than a T3.1 for seemingly simple counting loop? Is this from using elapsedMicros [unsigned long us;] comparison? [Putting a (uint16_t) cast on it doesn't help]
IDE_1.6.3 w/TLoader_1.24.b2
Code:
elapsedMicros EUwait;
...
while ( 300 > EUwait ) { inWhile++; }
Full Code below gives:
> inWhile==78 for LC OPTIMIZED 48MHz
> inWhile==77 for LC 48MHz
> inWhile==44 for LC OPTIMIZED 24MHz
> inWhile==846 for T3.1 OPTIMIZED 96MHz
> inWhile==422 for T3.1 OPTIMIZED 48MHz
Code:
#define qBlink() (digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) ))
void setup() {
digitalWriteFast(LED_BUILTIN, 0);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600); // USB
qBlink();
while (!Serial && millis() <= 3000) if (!(millis() % 500)) qBlink();
Serial.print("\n\n Hello World! ... ");
Serial.println(millis());
qBlink();
}
void loop() {
qBlink();
elapsedMillis waiting; // "waiting" starts at zero
elapsedMillis EMwait;
uint mStart, mStop, mMax = 0;
mStop = millis();
waiting = 0; // reset waiting back to zero
elapsedMicros EUwait;
int inWhile;
int inWhileMax = 0;
mStop = micros();
waiting = 0; // reset waiting back to zero
while (waiting < 10000) {
inWhile = 0;
EUwait = 0;
mStart = micros();
[B] while ( 300 > EUwait ) {
// Do what you must while waiting
inWhile++;
}[/B]
mStop = micros();
if ( inWhile > inWhileMax )
{
qBlink();
inWhileMax = inWhile;
Serial.print(" inWhile==");
Serial.print(inWhileMax);
}
if ( (mStop - mStart) > mMax )
{
mMax = mStop - mStart;
}
}
Serial.print("\ninWhile==");
Serial.print(inWhileMax);
Serial.print(" Max Time Seen==");
Serial.println(mMax);
}
PS: I should recode this with METRO to compare.
Last edited: