Speeding up Python

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2004
Posts: 4,141
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 947
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Speeding up Python

 
0
  #1
Jan 15th, 2005
I keep hearing that Python is about as slow as Java. Does anybody have experience with speeding things up?
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,858
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Speeding up Python

 
0
  #2
Jan 15th, 2005
>I keep hearing that Python is about as slow as Java.
Java can be comparable in speed to C++ or as slow as Christmas. It's not a good measure.

>Does anybody have experience with speeding things up?
Are you having problems with performance? If not, why bother? In my experience with Python, speed is rarely an issue if you actually bother to do things intelligently. Any moron can write code, but it takes work to write good code, and experience on top of that to write great code.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 436
Reputation: Chainsaw is an unknown quantity at this point 
Solved Threads: 11
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: Speeding up Python

 
0
  #3
Jan 15th, 2005
Taking a clue from my managers at work, you should tell the compiler to work SMARTER, not HARDER. That will help.

Oh, gee, I guess it doesn't help employees either.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,141
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 947
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Speeding up Python

 
0
  #4
Jan 15th, 2005
Thanks Narue and Chainsaw for your usual perspicacity.

I am just getting my feet wet with Python. If speed comes with experience, there might be hope. VPython is pretty impressive though! Just picked up info from another forum about "Swig" (?). A wrapper that allows Python to include C where speed might be of the essence.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 37
Reputation: EAnder is an unknown quantity at this point 
Solved Threads: 5
EAnder EAnder is offline Offline
Light Poster

Re: Speeding up Python

 
0
  #5
Jul 23rd, 2008
To speed up Python there are 3 things you could do that I know of:

Code Smarter: As ChainSaw pointed out. Try to simplify your programs. Don't rewrite things(there is a reason why a lot of modules are written in c, c++, and D. Not because they had to but because they are already compiled). Use threads and then reuse them. Make functions. Its the same as recycling.

Psyco(Did I spell the name right?): If you are using a 64 bit processor(I'm pretty sure its limited to a 64 bit) you can use the Psyco module and that speeds it up. I've heard its easy to use even for intermediate python programmers.

Compiling: I know python is interpreted but you can compile programs with py2exe(windows) or py2app(Mac), or PyInstaller(all i think)
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,141
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 947
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Speeding up Python

 
0
  #6
Jul 23rd, 2008
Originally Posted by EAnder View Post
To speed up Python there are 3 things you could do that I know of:

Code Smarter: As ChainSaw pointed out. Try to simplify your programs. Don't rewrite things(there is a reason why a lot of modules are written in c, c++, and D. Not because they had to but because they are already compiled). Use threads and then reuse them. Make functions. Its the same as recycling.

Psyco(Did I spell the name right?): If you are using a 64 bit processor(I'm pretty sure its limited to a 64 bit) you can use the Psyco module and that speeds it up. I've heard its easy to use even for intermediate python programmers.

Compiling: I know python is interpreted but you can compile programs with py2exe(windows) or py2app(Mac), or PyInstaller(all i think)
EAnder, thanks for your kind words. Python has proven to be quite addictive, and three and half years later I am still having fun. The Python interpreter has seen some architectual revamping and has gotten quit a bit faster over the years. Psyco compiles to 386 native code rather than virtual bytecode, and can speed things up 3 to 5 times. Narue was correct, I find that development speed is often more important then execution speed.

Programs like py2exe are actually programs that package your bytecode, the Python interpreter, and all required modules and resources into a self-extracting executable file. They are great, if you want to distribute your work to users without installed Python.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,071
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 299
woooee woooee is offline Offline
Veteran Poster

Re: Speeding up Python

 
0
  #7
Jul 23rd, 2008
Pypy is the faster Python. I have never tried it though. http://codespeak.net/pypy/dist/pypy/doc/home.html
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 984
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 222
Gribouillis's Avatar
Gribouillis Gribouillis is offline Offline
Posting Shark

Re: Speeding up Python

 
1
  #8
Jul 31st, 2008
I have some experience with speeding up python with swig. It allows you to access virtually any algorithm written in C or C++ from python. I used it for numerical analysis and also parsing. On such problems, this method is quit e efficient.

However, the most useful feature of swig is that you can wrap existing C librairies and access their functions from python. This method has been applied to many existing C librairies. Since thousands of potentially useful C libraries exist, this is a very good reason to experiment with swig, if you have a C compiler of course.

The usual warning applies: it's often difficult to predict exactly where are the botlenecks in your programs, which parts of the algorithms are going to slow down the whole program. So a good strategy can be to write a first version in python, and use profiling to determine which parts could be reimplemented in C. The golden rule is to avoid writing C code as much as possible, and speed up only key computational steps...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 4725 | Replies: 7
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC