Sign in to follow this  
Capitano

Python: profiling

Recommended Posts

Hi all,

i'm writing a short platformer game with python and pygame. Unfortunately, the whole thing is not really fast:/ So my idea was to profile the programm in order to find the problem.

At first i have some questions about it(never used "profiling" before):
is it right, that the results get better the longer I'm playing? Because all the stuff that is only done once on startup becomes less important over the time, and the average value gets more precise the longer everything runs.
Or have i a general error in reasoning?

What is the normal workflow in profiling a script that does not only runs from "top to bottom"?

Here is my first try with the "profile"-module and Gprof2Dot (http://code.google.com/p/jrfonseca/wiki/Gprof2Dot]gprof2dot): (ca. 10 seconds playingtime)
Link to profiling graph= http://imgur.com/wPZZA.png
My conclusion is that the most of the time is spend during the rendering process, especially with the "renderMapLayer"-Method,

greetings
Simon


Ps: Sorry for my bad english. I hope it's understandable..

Share this post


Link to post
Share on other sites
Hi,

I just finished a game using python and pygame, and I had the same performance problems you have even though it was just a remake of an NES game, tried the profiler and optimized my code until pygame itself became the major bottleneck. The game ran better but still performed badly on crappy Celerons.

Then I found 'psyco' which is an embedded JIT compiler for python, and performance problems disappeared. (gives python scripts 4x to 100x performance!)

Share this post


Link to post
Share on other sites
Yes, profile for as long as you can, if you want the best results for the whole game. Your reasoning is correct.

The normal workflow is simply to use the program in the way you normally would. If you only want to optimise one feature, use that feature a lot. The profiler just measures what the code is doing, so you need to make the code do the things that you want to measure. It's usually good to have a fixed length of execution to profile, so that you can compare results before and after a fix.

The graph is too big for me to spend time looking at it. Generally I just look at the text output from a profiler and see which 2 or 3 areas of the code use the most time. Then I look at those areas, and find the 2 or 3 slow functions... and so on, until I find something I can fix. I make the fix, then run the profiler again to see if it made a difference.

Share this post


Link to post
Share on other sites
First of all thanks Kylotan for the nice explanation!


>Then I found 'psyco' which is an embedded JIT compiler for python, and performance problems >disappeared. (gives python scripts 4x to 100x performance!)

Looks really nice, but doesn't work for me. because the game should run on a handheld (arm architecture)


So thanks both. My question is answered:)

And the performance thing... yey, don't think there is a general master solution.

greetings

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this