Skip to main content
gamedev.net
🔒 Locked

Python: profiling

Started by Capitano Sep 29, 2010 at 5:28 AM 2 replies 1.2k views
Original Post
Capitano
Capitano
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..
SAL1
SAL1
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!)
Kylotan
Kylotan
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.
Capitano
Capitano
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.