Python too slow?

sturlamolden sturlamolden at yahoo.no
Fri Jan 11 12:55:08 EST 2008


On 10 Jan, 03:10, Steven D'Aprano
<ste... at REMOVE.THIS.cybersource.com.au> wrote:

> You are correct that optimizing Python is hard. However, in many cases,
> the problem is not that Python is too slow, but the specific algorithm
> chosen by the programmer is slow, e.g. no compiler optimization is going
> to turn an O(n**2) algorithm into an O(1) algorithm.

This is possibly the number one cause of 'slowness' complained about
on mailing lists.


> The Original Poster says it takes one or two seconds to process an
> 800x600 GIF. That sounds believable: on my PC, it takes about five
> seconds to loop over range(800*600) and do a tiny bit of processing.
> Something like Psycho might speed that up a lot, possibly by an order of
> magnitude or two.

It seems the code he is referring to is doing k-means clustering on
each frame. The clustering is done by from SciPy's cluster module,
which is doing 'vector quantitization'. The algorithm is written in
plain C. It is not Python that is slow. It is the amount of processing
done on each frame. As the bottleneck is already in C, it cannot be
done any faster without radically changing the algorithm and/or the
hardware.















More information about the Python-list mailing list