Code speedup tips

Fernando Perez fperez528 at yahoo.com
Sun Mar 2 03:52:37 EST 2003


Sean Richards wrote:

> OK this was a big improvement. Using the original nested loop version it
> took ~12min for a 500x500 array, using array slices dropped the time to
> ~1min. That is a pretty significant reduction. One small thing I needed
> to do to get the rule to work correctly was add the line ..
> 'workspace[:] += current[1:-1,1:-1]'
> when you calculate the workspace. If we don't do this then on step 2 the
> centre pixel becomes white instead of staying black. This effect
> propagates until the end result is a diamond of alternating black and
> white pixels instead of a solid black diamond.
> That was a great help Carl, my total Python 'uptime' is only a couple of
> hours but it looks like it is going to be an excellent tool.

You should take a look at scipy, in particular the weave tool:
http://www.scipy.org/site_content/weave

Here:
http://www.scipy.org/site_content/weave/python_performance.html
you'll find a good comparison of various approaches to problems similar to
what you have.

Numeric is always the right starting point, and Carl's solution was
excellent.  But you may find situations where it's not enough.  And the
nice thing about python is that there's still a lot of options.

Look also at f2py (http://cens.ioc.ee/projects/f2py2e) if Fortran rocks your
boat.  As a tool, f2py is just amazing in how easy it makes it to wrap
existing fortran codes.

Finally, Pyrex and psyco are always options, but I'm not familiar yet with
them enough to say more about them.

Best,

f.




More information about the Python-list mailing list