2024-06-22 09:11 AM
Hi,
I have used different micro-controller boards for many years, Arduino, STM32 and ESP32. I have always used Arduino IDE for all my developments. Recently I have downloaded STM32Cube IDE to see how it works compared to Arduino IDE. I started porting different programs and they went pretty well.
In the past I have developed a program to test the speed of different micro-controller boards. The program starts with a larger prime number and checks if its a prime or not. then it does it over and over to see how many times it can checks in 60 seconds. Though it does only arithmetician integer operation, it gives me an idea how fast a board is.
So I ported the code from Arduino IDE to STM32Cube IDE, and compared the results for a blue pill STM32 board (STM32F103C8T6 ). I got very different results. Code compiled in Arduino IDE goes through many more loops than the Cube IDE. If I start with a prime number 1990661, with Arduino IDE code can check 589632 times if its a prime or not. For the same code on the same board flashed through STM32Cube IDE only can check 169176 times. This is about 3.5 times slower. I get similar speed difference when I start with a different prime number.
I have attached both Arduino and Cube IDE code and few picture for reference. Is there anything I am doing wrong that is causing STM32Cube IDE to run slower? I am new to Cube IDE and do not know much. Any help will be appreciated.
Solved! Go to Solution.
2024-06-22 09:32 AM - edited 2024-06-22 09:35 AM
Hi,
>Is there anything I am doing wrong
Yes. You didnt use a optimizer setting (i suppose).
In Arduino somewhere in the linked libs and defines and everything, there is optimizer set to -O2 or 3.
So try again in IDE, with optimizer set to -O2 (my usual setting), or -Ofast , for best speed.
here:
2024-06-22 09:32 AM - edited 2024-06-22 09:35 AM
Hi,
>Is there anything I am doing wrong
Yes. You didnt use a optimizer setting (i suppose).
In Arduino somewhere in the linked libs and defines and everything, there is optimizer set to -O2 or 3.
So try again in IDE, with optimizer set to -O2 (my usual setting), or -Ofast , for best speed.
here:
2024-06-22 09:47 AM
Great. I changed the setting to -Ofast and the loop count jumped to 609835 which is higher than Arduino IDE. Thanks for your suggestion.
2024-06-22 10:03 AM
Do you have aggressive settings for Optimization, ie -Os for speed
Does the clock start properly? HSE & PLL ?
printf("\n\nCore=%d, %d MHz\n", SystemCoreClock, SystemCoreClock / 1000000);
2024-06-22 10:08 AM
@Tesla DeLorean , your sure about : "ie -Os for speed" ?
In my GCC compiler here, its for size, -Ofast is for speed.
2024-06-22 11:30 AM
:)
But you dont compare "IDEs" here - you compare the optimizer settings, using same compiler (both use GCC).
So to learn/see , what compiler doing, look here :
Try different compiler on different cpu...then you see, what can happen.