With this script is my arduino Nano faster. Why ? #10789
Replies: 7 comments 5 replies
-
You did not show the result for Arduino. And you did not show all of the Arduino code. Compilers can do a lot of optimization, when variables are statically declared, which interpreters like Python cannot do. If the result is really in the µs range (<< 1 ms), then the compiler may have eliminated the loop. You may also try making in the Arduino code hex1 an argument of convert(). |
Beta Was this translation helpful? Give feedback.
-
Then I see no reason to continue working with Pico if Pico is so slow. I just found the Pico Board in Arduino and will try it. |
Beta Was this translation helpful? Give feedback.
-
I made your Arduino code to something reasonable and have put it on a Arduino Nano. It shows 24ms execution time. The issue with your test: both hex1 and rgb are static. So the optimizer in the compiler decides that it does not have to call convert 2500 times and eliminates the
|
Beta Was this translation helpful? Give feedback.
-
There is a chapter in the documentation about Optimization: https://docs.micropython.org/en/latest/reference/speed_python.html |
Beta Was this translation helpful? Give feedback.
-
You were right. The code was still zero optimized by the compiler. Another way to make it reasonable, telling the compiler not to assume that rgb and hex1 will keep their values between calls. Note that with Python even the type of variables can change.
|
Beta Was this translation helpful? Give feedback.
-
That's what modern compilers do. Arduino just uses the AVR compiler. To be sure, I looked at the generated assembly code, which shows, that without the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have now written a lot of scripts in Python and notice that my pico is getting slower and slower. Then I tried simple scripts. What the Arduino Nano can do in microseconds, the Pico does in 250,000 microseconds!??? Whats going on here? the cpu freq is running at 125000000.
This is Python with 250000 microseconds:
This is Arduino Nano:
Beta Was this translation helpful? Give feedback.
All reactions