No doubt a bunch of people here know all about this sort of stuff already, but for those (like me) who had never run a profiler on Python code before:
After listening to Mike Fletcher's talk on profiling at PyCon on Friday, I fired up cProfile on my Pyglet project, which was starting to get bogged down as I added more entities into the game. A really simple guide (plus screenshots of 'RunSnakeRun', a GUI tool to help interpret the output from cProfile) is here: http://www.vrplumber.com/programming/runsnakerun/ Lo and behold, I found out straight away that a single line of code was responsible for 80% of the time spent in my game's main loop. @property def verts(self): return list(self.polygon.exterior.coords)[:-1] This gets called whenever we need one of my game entitie's vert list. So this is dumb several times over, performance wise. I vaguely remember putting it in here as 'the simplest thing that could work' ages ago and then forgetting all about it. Replace this property with five lines that cache the returned verts in a ctype array speeded up the whole game by 4x - a very easy win. Moral of the story: cProfile really works. Jonathan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---
