How fast is Python? - MicroPython versus C++

preview_player
Показать описание
For many tasks in computer science, speed in running programs plays a crucial role. In the context of ESP32 microcontrollers, I would like to know if MicroPython would be an option compared to C++?

Music:
Attribution 4.0 International (CC BY 4.0)
Рекомендации по теме
Комментарии
Автор

So beautiful comparison and video. Checked one more time, if you need speed in your application don't use Micropython; if you need fast development in the application, Micropython is a good choice. My opinion is for users (like me) that we do have not super programming skills.

fernandosanchezhernandez
Автор

MicroPython is amazing in ease of development! I cannot even begin to describe how nice it is to not have to worry about things like data types, pointers, memory allocation, and the like! That said, it eats resources like nobody's business! Imagine if there was a MicroPython port of Nuitka...

For anyone wondering what Nuitka is, it's a cross-compiler that translates Python code into C code that behaves exactly as CPython would when running it. Makes things a lot faster and slightly less memory-intensive!

awesomecronk
Автор

Reminds me of the C64, Assembler vs Basic V2 :-)

wernerviehhauser
Автор

Thanks for your comparison, these take some effort! If you can share both codebases it would be helpful. This example is tough for MicroPython since looping math in the interpreter is about the worst-case scenario. There are many ways to improve the performance of MicroPython; the most extreme example is to use a C module - for example, in this case, we may want to use C for the Mandelbrot algorithm calculations. But even before dropping in to C, simple checks to ensure you're not abusing the GC, reallocating variables etc and use of the native/viper decorators could make a huge difference. It would be interesting to look at how we could improve the performance...

mattytrentini
Автор

Python or any interpreted Language is not good for microcontroller programming but for Computer Vision AI and Data Science python has lot more resources then C++..
Python is good for Computer and GPU Base Processing System Specially for Resources

microtechbdsystem-automati
Автор

Did you try using the native or viper code emitters? The native emitter produces machine code in the target instruction set and calls runtime functions written in C. The Viper emitter produces more optimized machine code that does the calculations with the instruction set itself. These emitters have some restricted functionality and produce more code which takes more RAM, but the speed increase is significant, and generally all it takes is a single decorator above whatever function is slow. There are some additional performance tuning tricks involving creating pointers in local scope that cache the memory location of dictionary lookups.

kkiller
Автор

suppose their is a wireless sensor node that reads data every 300ms and sends it over, for this kind of usecase micropython and c++ does not make much difference ! also for quick prototyping micropython is great !!

TheOverfittedModel
Автор

Can you share the code for the python demo? I bet I can make it faster.

zachsylvester
Автор

TL, DR: You know the answer. Just that life of an engineer is collecting some data points here and there.

AndreasDelleske
Автор

I came here after I realised that I can't directly read from DHT11 because micropython is actually to slow to read data from sensor xD
Yea I know, there's library for dht in micropython but it's no fun.

scuroguardiano
Автор

I think some is not good in your uPY optimization, i can run video and audio using stm32 @160mhz and esp32 @200mhz. I know c and c++ are faster but i think your uPY can be to much better .

Thank you for the video !!

HpsMexico-STmx
Автор

what about Rust embedded programming language ? i see some review to compare with embedded c to power arduino

mohamedfarid
Автор

How to run C++ code on esp32 is there any how to ?

Ekstrapolator
Автор

Not a big fan of Python, but I'm stumped by the difference in speed. Is this all interpreted or (I suppose) compiled to Bytecode? Why is the bytecode-interpreter so slow? Are the correct data types used? I guess the C++ Version uses floats which the ESP32s FPU can process natively.

bimoverbohm
Автор

Great video, but when it comes to performance C/C++ will always win, unless you code in pure assembly.
I think a fairer comparison would be between 2 frameworks that are both on the same level of abstraction like nanoFramework to microPython.

jacobuscoetsee
Автор

MicroPython works great for people who need only a bit of knowledge, and a Pi for a simple, slow operation. Station monitoring ✅ Drone ❌

JurieBoshoff-mf
Автор

Does it account for performance gain on C++ from using sprite? Since python library doesn't support sprite it will need to recalculate full framebuffer meanwhile C++ library will only need to update the potion of the framebuffer.

saikhamhein
Автор

I'm a very amateur programmer, yet I have had no trouble using the Arduino IDE. Why do I need to learn a slower language that claims to be easier to use but as far as I can see is not?

joeschembrie
Автор

It certainly shows how big overhead of python on embedded systems. But mandelbrot benchmark is overkill imo

Laptevwalrus
Автор

For C++, the programmer thinks, once, but for a long time.
For Python, the microcontroller thinks, every time as well
the programmer doesn't think at all.
Для С++ думает программист, один раз, но долго.
Для Python думает микроконтроллер, каждый раз, а
программист вообще не думает.

vvdvlas