[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 2:50 AM, Hugo Arts <hugo.yoshi@xxxxxxxxx> wrote:
My gut says this is most definitely the fastest way to go for small
numbers of snow flakes.
I suspect there is a certain point at which the numpy approach by Ian
wins out (especially if you can
optimize that a little more like Ian suggests, though I don't know
enough about numpy).
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.
I also agree with the profiling bit. About 99% of your main loop was those nested for loops.