[PYTHON] Cython on Raspberry Pi

When porting a program developed in Python to a CPU that is poorer than a PC like the Raspberry Pi, the slowness becomes noticeable.

I investigated the situation of Cython to see if it could be speeded up with as little effort as possible. (Scikit-learn and scikit-image use Cython to speed things up. Given that they can also be used on the Raspberry Pi, the Cython framework should work on the Raspberry Pi as well.)

I found a case of speeding up on Raspberry Pi using Cython. I'm investigating how to install Cython itself, sudo pip install cython Was found.

Speed of Python, at least for doing raw IO, is quiet disappointing. By using Cython (for the whole program), speeds becomes acceptable.

Identify functions that are bottlenecks and are worth rewriting -Write unit tests, -Based on Python, speed up by rewriting to pyx files. (Alternatively, write it in C / C ++ language and wrap it in Cython to speed it up.) -Confirm that the unit test is successful. Looks good.

With the C / C ++ source before using the NEON instruction C / C ++ source using NEON instruction It seems good to write and speed up with ARM.

Of course, it's important to do what you can optimize before Cython. It's easy to use the range () function in python2.7. Replaces the part replaced by xrange (). It is effective to use iterators and generators to process large lists without generating them.

Source of information

[1]:Raspberry, running Python http://www.student.tue.nl/W/r.mientki/running_python.html

[2]:User’s Guide » Installation on Raspberry Pi Install Cython from sources (debian package are outdated): http://kivy.org/docs/installation/installation-rpi.html

Recommended Posts

Cython on Raspberry Pi
pigpio on Raspberry pi
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi
Testing uart communication on Raspberry Pi
MQTT on Raspberry Pi and Mac
raspberry pi 4 centos7 install on docker
Install ghoto2 on Raspberry Pi (memo)
Try using ArUco on Raspberry Pi
OpenCV installation procedure on Raspberry Pi
Power on / off Raspberry pi on Arduino
Detect switch status on Raspberry Pi 3
Install OpenMedia Vault 5 on Raspberry Pi 4
L Chika on Raspberry Pi C #
Build wxPython on Ubuntu 20.04 on raspberry pi 4
Raspberry Pi backup
"Honwaka Notification Lamp" on Raspberry Pi Part 2
Detect "brightness" using python on Raspberry Pi 3!
USB boot on Raspberry Pi 4 Model B
Adafruit Python BluefruitLE works on Raspberry Pi.
Set swap space on Ubuntu on Raspberry Pi
Use the Grove sensor on the Raspberry Pi
Install docker-compose on 64-bit Raspberry Pi OS
Run servomotor on Raspberry Pi 3 using python
"Honwaka Notification Lamp" on Raspberry Pi Part 3
Working with sensors on Mathematica on Raspberry Pi
Build OpenCV-Python environment on Raspberry Pi B +
Detect temperature using python on Raspberry Pi 3!
Mount Windows shared folder on Raspberry Pi
Matrix multiplication on Raspberry Pi GPU (Part 2)
How to install NumPy on Raspberry Pi
I installed OpenCV-Python on my Raspberry Pi
Working with GPS on Raspberry Pi 3 Python
What is Raspberry Pi?
Why detectMultiScale () is slow on Raspberry Pi B +
GPGPU with Raspberry Pi
Detect slide switches using python on Raspberry Pi 3!
Try using a QR code on a Raspberry Pi
Detect magnet switches using python on Raspberry Pi 3!
Enjoy electronic work with GPIO on Raspberry Pi
Raspberry Pi Bad Knowledge
Let's do Raspberry Pi?
Power on / off your PC with raspberry pi
Use Grove-Temperature & Humidity Sensor (DHT11) on Raspberry Pi
Make DHT11 available on Raspberry Pi + python (memo)
Beginning cross-compilation for Raspberry Pi Zero on Ubuntu
Display CPU temperature every 5 seconds on Raspberry Pi 4
DigitalSignage with Raspberry Pi
Introduced Ceph on Kubernetes on Raspberry Pi 4B (ARM64)
Raspberry Pi 4 setup memo
Connect to MySQL with Python on Raspberry Pi
Raspberry Pi system monitoring
Build a Python development environment on Raspberry Pi
Build an Arch Linux environment on Raspberry Pi
Record temperature and humidity with systemd on Raspberry Pi
Build an OpenCV4 environment on Raspberry Pi using Poetry
Run LEDmatrix interactively with Raspberry Pi 3B + on Slackbot
Try using the temperature sensor (LM75B) on the Raspberry Pi.
Control brushless motors with GPIOs on Raspberry Pi Zero