Finding out what is making your Perl code slow with profiling

You can use the debugging module Devel: :DProf to profile your Perl code. This will give you a list of the functions that take the most time to execute.

First make sure you have the module Devel::DProf installed. On recent versions of perl is should be installed as default.

Run your app as follows:

perl -d:DProf yourcode.pl [your args]

This will create a file called 'tmon.out' in your current directory.

Now run dprofpp and you will see output similar to this (but with much more info):

%Time ExclSec CumulS #Calls sec/call Csec/c  Name
 100.00     - -0.000      1        -      -  main::someFunc
 0.00       - -0.000      1        -      -  strict::bits
 0.00       - -0.000      1        -      -  strict::import
 0.00       - -0.000      1        -      -  main::BEGIN

Now you know where to look in order to speed up your code.

You can also view a subroutine tree using dprofpp -T which may give you more clues about what's happening in your code.

Last updated: 06/10/2005