Speed of computation

Hello everybody,

I am new here. So, please forgive my ignorance of how this forum works. I have a general question. I have written a simple computational code that simply performs some relatively rudimentary mathematical calculations. I have tested the same code on Arduino Nano, Arduino Due, and ESP32. I let the program run for 1000 cycles and calculate the average time elapsed per computation cycle. Strangely enough, it takes about 280 us on Arduino Nano, 5000 us on Arduino Due, and 1300 us on ESP32 to run one of those computing cycles. Does that make any sense? Why would a slower 8-bit microcontroller take so much less to complete the computational cycle as compared to faster 32-bit microcontrollers? Could that be because the Arduino IDE is more optimized for ATMega328 and not as much for the other microcontrollers? Thanks a lot for your comments.

No, that doesn’t make sense.
Perhaps you are hitting an unexpected optimization. (For example, “double” on Due and Esp32 is 64 bits, but only 32bits on AVR. But usually other factors (clock rate, 32bit cpu) more than make up for that...)

Post the actual code for more detailed analysis.

Other optimizations could be the compiler seeing that your 1000 cycle test loop isn’t actually doing anything useful and stripping the core code out. This behaviour could be dependent on the target processor type and it can be amazing how far it goes and how much effort is required to trick it into executing all the code given to it.

Thanks a lot for your comments. That was really useful. Indeed, I have to force Arduino Nano to fully run the program. When I do that, Arduino Nano takes 8400 us per computing cycle whereas Arduino Une takes 5300 us.

Uno or Due?

Uno and Nano should have identical runtimes - the processor is the same.

Sorry! That was a typo. My keyboard (Macbook, surprise! surprise!) is acting out. I meant Due.