Ok, you guys have successfully nerd sniped me this morning... Here some experiments showing the use of code emitter to speed this code up massively. Link to code: https://github.com/jonnor/embeddedml/tree/master/handson/mic...
The results on ESP32S3 (M5Stick AtomS3U), running MicroPython 1.24.1. All times in seconds, for the 2000 number sort.
bubble.py 19.119
bubble_native.py 9.482
bubble_viper.py 0.904
heapsort_viper.py 0.02
So one can do 100x better without changing the algorithm, and 1000x by changing it :)
Microcontrollers are a constrained platform. They can be plenty fast - but it is much more important to use the tools available, compared to on PC. MicroPython has excellent tools available for this.