Slow Python - what can be done?

Stephen Horne steve at ninereeds.fsnet.co.uk
Thu Mar 18 20:14:01 CET 2004


On 18 Mar 2004 09:43:19 -0800, sewall93 at rocknroll.umcs.maine.edu
(Jason) wrote:

>Hey,
>
>I'm an experience programmer but new to Python. I'm doing a simple
>implementation of a field morphing techinique due to Beier and Neely
>(1992) and I have the simple case working in Python 2.3 - but it's
>REALLY slow.

My impression is that you should avoid the Point class. It's a pretty
trivial class, but each time it is instantiated or an instance
destroyed you get some overhead. Do that enough times and you get
speed issues. If you can live with tuples and non-member functions,
that may be some help.

Also, for the picture data itself, possibly you should look at the
numarray library. I haven't used it myself, but I suspect that it will
have lower overheads than a standard Python list.

http://www.pfdubois.com/numpy/


You also seem to be doing too much avoidable work in your inner loop.
For instance, you could swap your x and y loops, and calculate things
like y*self.data.size[0] once per row (rather than for every single
pixel). I imagine there are also aspects of the transform calculation
that could be done once per row to save time, though I haven't looked
that closely at what you are doing.


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk



More information about the Python-list mailing list