Does code on Arduino IDE run faster than CubeIDE?
Posted: Mon Oct 25, 2021 12:28 am
Hi there
I was developing a project on Arduino using a generic STM32H743VIT board. Due some drawbacks of the Arduino library, mainly concerning to ADC and time interrupts, I decided to change to STM32CubeIDE, that supposedly should be more efficient in utilizing the processor resources. After successfully make the transition to new code, the first tests were, let’s say, weird. Data processing was terrible slow. So I decided to make additional tests by measuring the computation time of sum, product, division and also some functions (cosine and exponential), and compare them with the same code running on Arduino IDE. The code I employed to measure the processor performance in CubeIDE and Arduino IDE were:
On STM32CubeIDE:
On Arduino:
To my surprise, Arduino was 100 times faster than CubeIDE. The measured times were: 3646 micro seconds, or 3.646 milliseconds on Arduino IDE and 79 milliseconds on CubeIDE. The empty loop elapsed time was subtracted from these values. Since my knowledge of CubeIDE configuration is far limited, I can only suppose that there are some wrong parameters, like clock or compilation options. Unfortunately I couldn't find any explanation on net over this problem, and I really believe that CubeIDE is at least as fast as Arduino. Does anyone can say what I’m doing wrong?
I was developing a project on Arduino using a generic STM32H743VIT board. Due some drawbacks of the Arduino library, mainly concerning to ADC and time interrupts, I decided to change to STM32CubeIDE, that supposedly should be more efficient in utilizing the processor resources. After successfully make the transition to new code, the first tests were, let’s say, weird. Data processing was terrible slow. So I decided to make additional tests by measuring the computation time of sum, product, division and also some functions (cosine and exponential), and compare them with the same code running on Arduino IDE. The code I employed to measure the processor performance in CubeIDE and Arduino IDE were:
On STM32CubeIDE:
Code: Select all
{float fl_2, fl_3;
uint32_t itop = 1000000;
fl_2 = 1;
fl_3 = 0;
to = HAL_GetTick();
for (i = 0; i < itop; i++)
{
fl_2 = fl_2 + fl_3;
fl_3 = fl_2 + fl_3;
}
tf = HAL_GetTick() - to;
CDC_print_cp("Float sum (ms): ");
CDC_print_int((tf - tloop)/2);
CDC_print_ln();}
Code: Select all
{float fl_2, fl_3;
uint32_t itop = 1000000;
fl_2 = 1;
fl_3 = 0;
to = micros();
for (i = 0; i < itop; i++)
{
fl_2 = fl_2 + fl_3;
fl_3 = fl_2 + fl_3;
}
tf = micros() - to;
Serial.print("Float sum (ms): ");
Serial.print((tf - tloop)/2000);
Serial.println();
Serial.println();}