dwalton76 / rubiks-color-resolver

Resolve rubiks cube RGB values to the six cube colors
MIT License
34 stars 15 forks source link

micropython vs python3 performance #6

Closed dwalton76 closed 5 years ago

dwalton76 commented 5 years ago

python3 takes 250ms

time ./usr/bin/rubiks-color-resolver-micropython.py --filename test-data/3x3x3-random-08.txt

micropython takes ~1050ms

time ./usr/bin/rubiks-color-resolver-micropython.py --filename test-data/3x3x3-random-08.txt

Why is micropython 4x slower than python? You cannot do -m cProfile with micropython to profile it. With python3 most of the time is spent in delta_e_cie2000() but I do not know that that is the case with micropython. Note that with python3 we are caching the cie2000 results, if we turn that off it still only takes ~420ms.

Find a way to profile micropython so we can figure out why the perf is so bad.

dwalton76 commented 5 years ago

Perf suggestions here: http://docs.micropython.org/en/v1.9.3/pyboard/reference/speed_python.html

and this post suggest that creating float objects is very expensive https://forum.micropython.org/viewtopic.php?t=262#p1265

Try creating const() for as many things in delta_e_cie2000 as possible.

dwalton76 commented 5 years ago

The const() thing didn't seem to help any. For now I am going to resolve this by having micropython compute color distance via euclidean instead of cie2000. Computing the euclidean distance is drastically easier. Fixed via 665fdff393acb099420b898ad19bcda8f843cc0e