| | |
Speeding up Python
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
>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.
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
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.
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!
•
•
Join Date: Feb 2008
Posts: 37
Reputation:
Solved Threads: 5
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)
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)
•
•
•
•
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)
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!
•
•
Join Date: Dec 2006
Posts: 1,071
Reputation:
Solved Threads: 299
Pypy is the faster Python. I have never tried it though. http://codespeak.net/pypy/dist/pypy/doc/home.html
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...
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...
![]() |
Similar Threads
- News Story: It’s Like AJAX for Ruby and Python (Ruby)
- News Story: 450 bugs consumed by Python (Python)
Other Threads in the Python Forum
- Previous Thread: Writing TO Excel file
- Next Thread: Problem: Running .pyw or Py2Exe app in background
Views: 4725 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for Python
accessdenied address ansi backend beginner changecolor class code conversion coordinates copy corners curves customdialog dan08 dictionary directory dynamic edit examples excel feet file float font format ftp function generator getvalue gui halp homework i/o iframe images import info input ip java line linux list lists loop mouse mysql newb number numbers output panel parsing path port prime print program programming projects py2exe pygame pyqt python queue random rational recursion recursive screensaverloopinactive scrolledtext server ssh stamp statictext string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial type ubuntu unicode url urllib urllib2 variable whileloop windows write wxpython






