Benchmarking python speed on the Raspberry Pi

In the previous post I looked at the speed of the Pi for a particular floating point intensive simulation algorithm, coded in C. By running the code on the Pi and a couple of laptops I have available, this gave a useful indication of how fast the Pi hardware is relative to some other PCs. However, for languages other than C (and actually, even for C, to some extent), the speed of the code can depend as much on the implementation of the language (interpreter, compiler, byte-code compiler, virtual machine, etc.), as on the actual hardware. So in addition to knowing how fast your hardware is in theory, how fast your target language will run in practice is in fact the more relevant consideration. So, if python is your preferred language, knowing that the Pi should in principle be around the speed of a netbook is no good if the only python interpreter available for the Pi runs very slowly. In this post I’ll look at the speed of a simple python code running on the Pi and a couple of laptops I have.

In the previous post I demonstrated that of the currently available Debian-based distributions, only Raspbian has proper hard-float support and that this performs many times faster than other distros for floating-point intensive codes. I showed that a particular floating point intensive C code ran around at around half the speed of my netbook. Here we will look at the equivalent code in python. We will use the code “”:

import random,math
def gibbs(N=50000,thin=1000):
    print "Iter  x  y"
    for i in range(N):
        for j in range(thin):
        print i,x,y

from this post over on my main blog. On my netbook, this code runs in 20 minutes, 31 seconds.

time python > /dev/null

However, on Raspbian, the code takes 150 minutes, 43 seconds. This is around 7 times slower than on my netbook. This is around 3 times slower than I would expect based on the C code. This suggests that the python interpreter for Raspbian is relatively inefficient.

For comparison purposes, this code runs in 3 minutes 52 seconds on my fast laptop. This is around 5 times faster than my netbook, which is roughly what I would expect based on the relative performance of the C code, which was around 6 times faster.

If anyone has any explanation for the relatively poor performance of python on Raspbian I’d be very interested to know…



Published by


I am Professor of Stochastic Modelling within the School of Mathematics & Statistics at Newcastle University, UK. I am also a computational systems biologist.

3 thoughts on “Benchmarking python speed on the Raspberry Pi”

  1. My guess without you sending me your spare Pi 😉 would be memory access speed. It looks like the L2 cache may be disabled by default. Try turning it on and look for a performance boost. GPU performance will suffer though.

  2. I’ve upgraded firmware and kernel with "rpi-update", and L2 cache should be enabled for recent Raspbian kernels (it is not disabled in /boot/config.txt). Runtime has improved to 140 minutes 10 seconds, but is still a long way off what I would expect.

Leave a Reply to Anonymous Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s