Closed hasenradball closed 6 months ago
Memory usage change @ 03da13c1767f6dd25cc1415e1c0258244dcebc9b
Board | flash | % | RAM for global variables | % |
---|---|---|---|---|
arduino:mbed_nano:nanorp2040connect |
:small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:megaavr:uno2018:mode=on |
:grey_question: -12 - +4 | -0.02 - +0.01 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrvidor4000 |
:small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrwifi1010 |
:small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:nano_33_iot |
:small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
I don't see the change. formatting changed. while
instead for
and return
instead of break
. I don't see what it does differently.
and the connection time is same too.
@JAndrassy then you should have a closer look.
see the status =-1;
so yes, but why the other changes in the code? you must adapt to code style of the original source code and not change more lines than needed.
Memory usage change @ e8b31b43bb17df044b09f003e58d31805e9649d1
Board | flash | % | RAM for global variables | % |
---|---|---|---|---|
arduino:mbed_nano:nanorp2040connect |
:small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:megaavr:uno2018:mode=on |
:grey_question: -2 - +4 | -0.0 - +0.01 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrvidor4000 |
:small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:mkrwifi1010 |
:small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
arduino:samd:nano_33_iot |
:small_red_triangle: 0 - +4 | 0.0 - 0.0 | 0 - 0 | 0.0 - 0.0 |
Hi @JAndrassy,
added now only the necessary stuff to improve the existing WiFi.begin()
methods.
Here the summary:
int16_t
due to NO_SHIELD needs value 255status
also to int16_t
status = -1;
in case of timeoutlooks much better.
@JAndrassy
one hint why I want to change the loop from for
to while
was the while loop is much faster than the for loop.
here a small result (while is 1/3 faster):
=== Loop Test ===
Duration while loop: 6 us
Value: 2147483648
Duration for-loop: 9 us
Value: 2147483648
#include <Arduino.h>
unsigned long loop_test1() {
size_t counter {0};
unsigned long value {1};
while (value < 2147483648) {
++counter;
value = value * 2;
}
return value;
}
unsigned long loop_test2() {
volatile unsigned long value {1};
for (size_t counter = 0; value < 2147483648; ++counter) {
value *= 2;
}
return value;
}
void setup() {
Serial.begin(9600);
while (!Serial) {
yield();
}
Serial.println("\n\n === Loop Test === \n\n");
unsigned long tic {micros()}, toc;
unsigned long result = loop_test1();
toc = micros();
Serial.print("Duration while loop: ");
Serial.print((toc-tic));
Serial.println(" us");
Serial.print("Value: ");
Serial.println(result);
tic = micros();
result = loop_test2();
toc = micros();
Serial.print("Duration for-loop: ");
Serial.print((toc-tic));
Serial.println(" us");
Serial.print("Value: ");
Serial.println(result);
}
void loop() {
}
that would lead me to investigate if it is really the same loop logic. I trust C++ compiler to generate the same assembly from both cases.
Hi @JAndrassy,
This can easily checked normally by godbold.
From my expirience as SW Developer I have often seen that while is faster than for loop. Thats the reason I suggested this.
If thats the case you will get 30% more performance for free.
I always say trust is fine but control is better.
Hi @JAndrassy,
I made some screenshots for you.
a) First example while
loop:
==> You see 15 lines of Assembler instructions.
b) Second Example for
loop:
I hope I compared apples with apples. It seems to be the same code. :-)
why to improve?
With this rework the following benefits added:
-1
is possible => indicated timeouttested on