random4631
Posts: 5
Joined: Tue Apr 29, 2014 7:30 am

Python is barely usable on Raspbian

Tue Apr 29, 2014 7:36 am

Hi,
I don't know if you guys have the same issue but it seems that Python executables are really really slow on my pi. For example, just running "pip" with no args takes about 5 seconds of 90% cpu just to print the help message.

Does anybody else have the same issue? And what exactly is causing it?

User avatar
joan
Posts: 14566
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 7:43 am

Python is perfectly usable on the Pi.

Perhaps pip is a bad choice of benchmark.

random4631
Posts: 5
Joined: Tue Apr 29, 2014 7:30 am

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 7:52 am

Flexget is also extremely slow on my machine. It takes about 20 seconds to print the help message.
how is the cpu usage on your machine? Do you know what could be causing the bad performance on mine?

User avatar
DougieLawson
Posts: 36818
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 7:55 am

What else is running? It may be worth killing that bitcoin miner when you want to run python :roll:

Take a look with the top command.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 7:58 am

I am using python heavily on my raspberries. I have not seen that they aer slow.
I have not used pip though, so can't comment that. But it seems to be a package managing thing, so does it really matter if it is slow?

I think the main thing is that python scipts work fast? Or do you see slowness in real python?

User avatar
joan
Posts: 14566
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 7:59 am

To the best of my knowledge I have never used pip or flexget.

I know pip is some sort of Python package management system. It needs to access the internet to generate an index of source distribution archives. That can be time consuming on any machine. I'd think especially so the first time through.

I have never heard of flexget but it sounds like a similar tool and may have similar problems.

random4631
Posts: 5
Joined: Tue Apr 29, 2014 7:30 am

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 8:01 am

I was keeping an eye on "top". Like I said, "pip" and "flexget" were using 90+% of the cpu.

I'm not really worried about "pip". My main issue is "flexget"'s performance. Does anybody know of a python benchmarking tool or something that I can use to confirm the performance issue?

random4631
Posts: 5
Joined: Tue Apr 29, 2014 7:30 am

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 8:04 am

it's taking pip over 5 seconds just to print the help message. Not index or download packages. All the while using 90+% of the cpu. I don't think that is normal.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24569
Joined: Sat Jul 30, 2011 7:41 pm

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 8:19 am

What performance do you see on other Python applications? Sounds to me like this might be Pip/Flexget specific. Do they both access the network whilst running (even with just help)?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 8:24 am

quick test from my raspberry: Build file test.py:

Code: Select all

import time
x = 0
def doit1(i):
    global x
    x = x + i

list = range(100000)
t = time.time()
for i in list:
    doit1(i)

print "%.3f" % (time.time()-t)

$ python test.py
0.595

User avatar
pluggy
Posts: 3635
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
Contact: Website

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 9:38 am

The Pi has a puny CPU, if you're used to a late model fast X86 processor, the Pi is a couple of orders of magnitude slower.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......

random4631
Posts: 5
Joined: Tue Apr 29, 2014 7:30 am

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 9:59 am

shuckle, I got a 10 times average of 0.885

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Python is barely usable on Raspbian

Tue Apr 29, 2014 10:05 am

Sorry, I run it in my 1100MHz overclocked raspi.

Three runs in base 700MHz raspberry gives:
$ python koe.py
0.895
$ python koe.py
1.029
$ python koe.py
1.101

I have a little other load there also, so this matches pretty well with yoru results.

As pluggy said...this is what raspberry CPU can do. It can not break records. But it works well for me.

ianholing
Posts: 1
Joined: Thu Jan 15, 2015 8:14 am

Re: Python is barely usable on Raspbian

Thu Jan 15, 2015 8:26 am

¿1 second to just count to 100.000? That was acceptable at 1990s but not today imo.

I've tried to use it for a proyect but I just can't do it with this times. Imo Raspberry is not even barely usable in raspberry.. I hope it was a configuration mistake or something similar but this are my tests for the same code in go (i.e.):

Code: Select all

pi@raspberrypi ~ $ python3.2 count.py 
0.972
pi@raspberrypi ~ $ go run count.go 
0.0014190000000000001
That's crazy :/
Am I doing something wrong? There are some kind of configuration of python that it haven't for default?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24569
Joined: Sat Jul 30, 2011 7:41 pm

Re: Python is barely usable on Raspbian

Thu Jan 15, 2015 9:19 am

ianholing wrote:¿1 second to just count to 100.000? That was acceptable at 1990s but not today imo.

I've tried to use it for a proyect but I just can't do it with this times. Imo Raspberry is not even barely usable in raspberry.. I hope it was a configuration mistake or something similar but this are my tests for the same code in go (i.e.):

Code: Select all

pi@raspberrypi ~ $ python3.2 count.py 
0.972
pi@raspberrypi ~ $ go run count.go 
0.0014190000000000001
That's crazy :/
Am I doing something wrong? There are some kind of configuration of python that it haven't for default?

??? You seem to be under the mistaken belief that the Pi is as fast as a modern desktop! If it was, it would cost the same as a modern desktop.

It has a 700Mhz ARv6 processor, equivalent to about a 300-400Mhz Pentium2.

If Python is too slow (and it will be for some applications), use a compiled language which will be much faster, like C or C++.

Or write better code.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

Sleep Mode zZ
Posts: 319
Joined: Sun Aug 19, 2012 5:56 am
Location: Finland

Re: Python is barely usable on Raspbian

Thu Jan 15, 2015 10:06 am

ianholing wrote:¿1 second to just count to 100.000? That was acceptable at 1990s but not today imo.

I've tried to use it for a proyect but I just can't do it with this times. Imo Raspberry is not even barely usable in raspberry.. I hope it was a configuration mistake or something similar but this are my tests for the same code in go (i.e.):

Code: Select all

pi@raspberrypi ~ $ python3.2 count.py 
0.972
pi@raspberrypi ~ $ go run count.go 
0.0014190000000000001
That's crazy :/
Am I doing something wrong? There are some kind of configuration of python that it haven't for default?
You are comparing an interpreted language to a compiled language. If you want speed, use a compiled language like Go or C. Python is designed with other priorities. If you don't need or appreciate what Python has to offer and/or need the speed of execution, it is good that there are plenty of options to choose from.
Last edited by Sleep Mode zZ on Thu Jan 15, 2015 2:38 pm, edited 1 time in total.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Python is barely usable on Raspbian

Thu Jan 15, 2015 1:54 pm

Just to give you an idea of the speed of a Raspberry vs an older desktop vs a modern desktop, here are the compile times of the same software package on different hardware.

Raspberry pi ~1 hour 45 minutes
Beaglebone -~ 50 minutes
Dell 690 (3 Ghz quad core) ~6 minutes
new computer ~ 3 minutes.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24569
Joined: Sat Jul 30, 2011 7:41 pm

Re: Python is barely usable on Raspbian

Thu Jan 15, 2015 2:52 pm

I wonder how much of that time is I/O? Someone should do the compile test using an SD card as the input/output media.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

User avatar
blachanc
Posts: 459
Joined: Sat Jan 26, 2013 5:03 am
Location: Quebec,canada(french)

Re: Python is barely usable on Raspbian

Thu Jan 15, 2015 4:10 pm

jamesh wrote:I wonder how much of that time is I/O? Someone should do the compile test using an SD card as the input/output media.
That is so true. IO is often a perf killer that is overlooked:

as a comparison (latest greatest cruncher & NFS server), building a simulation database for an ASIC that takes 1.2 GIG of disk space will takes 20 minutes when on a NFS server, versus 5 minutes when built on the local disk of the same cruncher.

Could be interesting also to perform the python tests on a USB hard drive connected to the PI vs the SD card.

Ben
Autism/Asperger syndrome: what is your score on this quiz?
http://www.raspberrypi.org/forums/viewtopic.php?f=62&t=70191

beruic
Posts: 28
Joined: Sun Jan 29, 2012 1:37 pm

Re: Python is barely usable on Raspbian

Thu Jan 14, 2016 12:48 pm

Any news on this?
It's killing me how slow pip is just to show the help message, or doing a simple freeze.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Python is barely usable on Raspbian

Thu Jan 14, 2016 12:55 pm

That's just how it works. There's nothing you can do about it.
There are 10 types of people: those who understand binary and those who don't.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12527
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Python is barely usable on Raspbian

Thu Jan 14, 2016 1:05 pm

Tried the Python code above on my modern PC (after modifying the print command for Python 3.4) so this:

Code: Select all

import time
x = 0
def doit1(i):
    global x
    x = x + i

list = range(100000)
t = time.time()
for i in list:
    doit1(i)

print ("%.3f" % (time.time()-t))
and it came out as 0,03, which is just about 20 times faster than the PI's 0.595 second.
seems reasonable to me, python isn't that fast! and a PI being twenty times slower than a modern PC seems a good estimate of the PI's speed.
¿1 second to just count to 100.000? That was acceptable at 1990s but not today imo.
In defense of python. the above code is not simply counting to 100.000, this code does it better, but modified for 1000.000 as otherwise it was too fast!

Code: Select all

import time

list = 1000000
t = time.time()
i = 1
while i < list:
	i = i+1

print ("%.3f" % (time.time()-t))
That code scored 0.15 sec on my PC.

By the way, which PI are you using?

beruic
Posts: 28
Joined: Sun Jan 29, 2012 1:37 pm

Re: Python is barely usable on Raspbian

Thu Jan 14, 2016 1:12 pm

I have raised this issue with pip as it seems this issue is not unique to the Raspberry Pi.
https://github.com/pypa/pip/issues/3360

jahboater
Posts: 4926
Joined: Wed Feb 04, 2015 6:38 pm

Re: Python is barely usable on Raspbian

Thu Jan 14, 2016 6:29 pm

My Pi2 executes the python3 script in 0.246 seconds.
About 17 times slower than my PC which cost 45 times as much, and uses about 150 times as much electricity. The Pi2 is a bargain!
"We are in the beginning of a mass extinction, and all you can talk
about is money and fairy tales of eternal economic growth."
- Greta Thunberg

beruic
Posts: 28
Joined: Sun Jan 29, 2012 1:37 pm

Re: Python is barely usable on Raspbian

Fri Jan 15, 2016 2:03 pm

jahboater wrote:My Pi2 executes the python3 script in 0.246 seconds.
About 17 times slower than my PC which cost 45 times as much, and uses about 150 times as much electricity. The Pi2 is a bargain!
Could you try to run

Code: Select all

$ time pip -h
and

Code: Select all

$ time pip3 -h
if you have Python 3, and post the times from both machines?

Return to “Troubleshooting”