[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Bullet Tests
On Tue, Apr 10, 2007 at 04:49:17AM -0400, Kris Schnee wrote:
> I tried building a bullet recycling system, and I don't see a big
> performance boost from it -- but it's hard to tell.
>
> If you want to check it out, see:
> http://kschnee.xepher.net/code/cestus_mk2.py
> http://kschnee.xepher.net/code/cestus_mk2%20(no%20recycling).py
>
> Those are versions of the shooter game hacked to run for 500 frames with
> the player being invincible and the controls disabled, and the random
> number generator "seeded" so that the same enemy pattern always appears.
>
> The weird thing is, in the first copy -- the one with recycling -- the
> enemies mysteriously stop firing after a while. I put in a debug line
> (currently commented out; search for "The guns -- they've stopped!") to
> report on how many player, enemy, and spare bullets are in-game. That
> line reports that bullets are getting recycled, all right, but the
> enemies just stop shooting!
>
> Anyway, the framerate difference I got was only something like 33 vs. 30
> (recycling and not). It could be that my "graphics" and game logic are
> too poor, so I tried running a test with the screen drawing disabled,
> and got FPS of 38 vs. 37.
>
> My Bullet class is really simple, though. You might get more of a
> performance difference if you're using sentient 3D particle-trail
> bullets with Wikipedia access.
>
> Kris
> (Bullet Bill: "*Sniff* I'm gonna miss ol' Buck -- he was a good shot!")
>
Guess-and-check performance optimization is a mug's game. Don't guess,
just profile. Make sure you have the profile module installed, and do:
import profile, pstats
profile.run('main_game_loop()', 'profile.dat')
p = pstats.Stats('profile.dat')
p.sort_stats('time').print_stats(30)
More docs hereish: http://docs.python.org/lib/profile-instant.html
---
James Paige