13

I've been benchmarking the Pi on some of my simulation codes, relative to a couple of laptops I have. My codes tend to be floating point intensive, so I've been using Raspbian (which turns out to be much faster) due to its hard-float support. I have the same simple code in several different languages. Obviously python code is slower than C code whatever platform I use, but on the Pi it appears to be relatively more slow, by a factor of around 3. Does anyone know why the python interpreter is likely to be relatively slow on the Pi, and is this something that is likely to be fixed?

Here is the test:

import random,math

def gibbs(N=50000,thin=1000):
    x=0
    y=0
    print "Iter  x  y"
    for i in range(N):
        for j in range(thin):
            x=random.gammavariate(3,1.0/(y*y+4))
            y=random.gauss(1.0/(x+1),1.0/math.sqrt(2*x+2))
        print i,x,y

gibbs()

From this blog post about the experiment.

  • 2
    Self promotion is fine (within reason) but all your blog link really added to the question was the code, so I've moved it here instead. – Jivings Jul 2 '12 at 20:05
  • 2
    Um, it also contained details and timings and other potentially useful background which substantiated the claim that python is slower relative to C on the Pi than on Intel based linux machines, which was kind of the point of the question... – Darren Wilkinson Jul 2 '12 at 20:18
  • 2
    I read the whole post, I don't think it contributed information incredibly relevant to the question. And asking everyone to read a page of information before they can answer your question is not going to get you a lot of answers. Programmers are by definition, lazy. We need all the information in easy to digest chunks :) – Jivings Jul 2 '12 at 20:24
  • 8
    That's a judgement call that I'm fine with, as I'm an easy-going kind of guy... But I am a bit concerned that this zealous over-editing of almost every question posted on this site is likely to deter people from participating. I know it's done with the best of intentions, but you know what they say about the road to Hell... I really think it's something that all of you very active question editors should take some time to think and chat about. It would be a real shame if this site didn't take off because of the actions of a few well-intentioned but misguided individuals. – Darren Wilkinson Jul 2 '12 at 20:48
  • 1
    Stupid question... were you running the same version of python on both sides of the equation? I would expect on the same hardware, python3 will run the same code faster than python2 because range on python3 is an iterator and on python2, it creates the list which is less efficient (use xrange on python2)... see for example stackoverflow.com/questions/94935/… – Foon Apr 3 '13 at 1:07
7

I would guess that the Python interpreter is simply not optimized for ARM. Python might have been optimized for the other platforms. In my experience, this is true for software like OpenSSH, so I assume it's similar for Python.

2

Python probably suffers from lack of cpu cache. I'm not sure how you can measure that easily though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.