Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4c3c6cfe3d
Fetching contributors…

Cannot retrieve contributors at this time

79 lines (44 sloc) 2.343 kb

Games generally need to be as tight in using memory and CPU as possible. Although Perl is generally thought to be too slow for games, this is not always the case. Usually Perl will be quicker to develop code in after which many steps can be taken to profile the code for production use. However the key step is to first write code without concern of optimizations.

Preparing a Game for Profiling

We will begin by profiling a simple collisions demo script. The script is provided for you in the code_listings/profile_0.pl on HTTPS://GitHub.Com/PerlGameDev/SDL_Manual site. Get the repository, extract it and run:

    perl code_listings/profile_0.pl

Right now the code will be running the whole game, which is a problem for profiling as we want the game loop to run only a specified number of times. This can be accomplished by adding a run counter.

    +my $profile_counter = 0;

Then in our game loop callbacks we will stop the application after a certain amount of calls.

    +$app->add_move_handler( sub{ $app->stop() if $profile_counter++ > 100 } );
     $app->run();

Run this code which is provided in code_listings/profile_1.pl, and it will close sortly after a rendering the first 100 frames.

        perl code_listings/profile_1.pl 

Profiling with NYTProf

First incase you don't have the profiler go ahead and get the module from cpan.

        cpan Devel::NYTProf 

Next run the profiler on our prepared sample of the game.

        perl -d:NYTProf code_listings/profile_1.pl 

Once that has finished running we will generate HTML reports.

        nytprofhtml

Once the HTML reports are done we will go ahead an open them in a broswer.

        firefox nytprof/index.html 

The Reports

What is called often? Load time? Run time? In the game loop?

Optimize

Algorithms

Are you doing something inefficent? Is there a well know algorithm to do this?

Design Patterns

Any design patterns that can do what you need? Maybe use modules that do this for you.

XS

Nothing else left? Move it to C.

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 1:

Unknown directive: =head0

Around line 9:

Deleting unknown formatting code U<>

Jump to Line
Something went wrong with that request. Please try again.