[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] is there a way to optimize this code?

On Mon, Aug 17, 2009 at 6:32 PM, Ian Mallett<geometrian@xxxxxxxxx> wrote:
> What I like about the OP's approach, and about the numpy version of it, is
> that it's perfectly scalable to any number of particles.  The program as I
> modified it runs ~30 fps--but it runs about 30fps whether you add random
> particles 8 or 128 times (yes, I tried.  Incredibly dense snowfall piles up
> extremely quickly and is neat to see).  I suspect a approach that keeps
> track of all the particles individually might start out faster and degrade,
> especially if done with unoptimized Python.

This is definitely true, however if you keep the amount of snow
particles constant but increase the resolution
you will see big performance hits. There is a classic performance
trade-off, with solution number 1 being independent of the screen
resolution and solution two being independent of the number of
particles. The right approach definitely depends on the use case, and
I think it's definitely worth trying both and comparing them.

It's an interesting example of how different algorithms lead to vastly
different performance characteristics.