Python and PyPy on Raspberry Pi 1 nad 2 – Benchmarks
The new Raspberry Pi is out. How fast is it? About 6x they say, 6x using 4 cores! What about one core? How fast will your code run? Let’s use The Grand Unified Python Benchmark Suite and check it. What is it?
This project is intended to be an authoritative source of benchmarks for all
Python implementations. The focus is on real-world benchmarks, rather than
synthetic benchmarks, using whole applications when possible.
Where to get the benchmarks?
Benchmarking is hard, showing the results in easy and readable way is even harder. So don’t trust me. Try it yourself. You can get all benchmarks from python mercurial repo via
hg clone https://hg.python.org/benchmarks/
or, if you don’t have mercurial installed, you can download zip file
This tests are designed to compare different python implementations. Python actually has many implementations, here are the four most popular:
- cpython – implemented in C, probably you are using it
- jython – implemented in java
- ironpython – implemented in C#
What is PyPy?
PyPy is a replacement for CPython. It is built using the RPython language that was co-developed with it. The main reason to use it instead of CPython is speed: it runs generally faster
Read more on their site
Before running the benchmarks you need to install PyPy. If you are using Rasbian just run:
sudo apt-get install pypy
Using this command you will install PyPy 2.2. The newest version is PyPy 2.5, which you can download here, there is even version for Rasbian.
How to run the benchmarks?
Running this benchmarks on Raspberry Pi 1 will take almost 20 hours.
To start benchmarks just run:
python perf.py -r -b default /usr/bin/python /usr/bin/pypy
How long does it take to run?
- Raspberry Pi 1 – 19.5h
- Raspberry Pi 2 – 6h
- My laptop with i7 2.7GHz CPU – 20 minutes
It looks like just switching to Raspberry Pi 2 may speed up your code about 3.3 times. And there are still 3 more cores waiting for you!
The above plot represents Python on Raspberry Pi 2 benchmark times normalized to Raspberry Pi1. Smaller is better.
The above plot represents PyPy on Raspberry Pi 2 benchmark times normalized to Raspberry Pi1. Smaller is better.
PyPy 2.2 vs PyPy 2.5
By default on Rasbian you can install version 2.2 and the current version is 2.5. Does it make sense to use newest version?
Pypy vs Python on Pi 2
PyPy is faster than the most popular C implementation, at least this is what we can see on their site: http://speed.pypy.org/. It should be almost 7x faster, but is it?
Do you want to see more RaspberryPi 2 benchmarks? Here you go:
There is a blog post on Raspberry Pi site with some benchmarks. Adafriut made a great overview of new Pi with some good benchmarks. LinuxVoice has a nice overview with some performance tests. Alex Eames made nice video with power and performance measurements. On Hackady you can also see some nice benchmarks. Purbeck STEM club made really nice Minecraft “benchmark” with many BUMs and BAMs. What about database performance? Go and see this post from Nigel Day on Raspberry Pi forum. Trusted Reviews also has interesting article about Pi performance.