From: PerlFAQ Server on
This is an excerpt from the latest version perlfaq3.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at .


3.6: How do I profile my Perl programs?

(contributed by brian d foy, updated Fri Jul 25 12:22:26 PDT 2008)

The "Devel" namespace has several modules which you can use to profile
your Perl programs. The "Devel::DProf" module comes with Perl and you
can invoke it with the "-d" switch:

perl -d:DProf

After running your program under "DProf", you'll get a tmon.out file
with the profile data. To look at the data, you can turn it into a
human-readable report with the "dprofpp" program that comes with


You can also do the profiling and reporting in one step with the "-p"
switch to "dprofpp":

dprofpp -p

The "Devel::NYTProf" (New York Times Profiler) does both statement and
subroutine profiling. It's available from CPAN and you also invoke it
with the "-d" switch:

perl -d:NYTProf

Like "DProf", it creates a database of the profile information that you
can turn into reports. The "nytprofhtml" command turns the data into an
HTML report similar to the "Devel::Cover" report:


CPAN has several other profilers that you can invoke in the same
fashion. You might also be interested in using the "Benchmark" to
measure and compare code snippets.

You can read more about profiling in *Programming Perl*, chapter 20, or
*Mastering Perl*, chapter 5.

perldebguts documents creating a custom debugger if you need to create a
special sort of profiler. brian d foy describes the process in *The Perl
Journal*, "Creating a Perl Debugger", , and
"Profiling in Perl" . has two interesting articles on profiling: "Profiling Perl", by
Simon Cozens, and "Debugging and Profiling
mod_perl Applications", by Frank Wiles, .

Randal L. Schwartz writes about profiling in "Speeding up Your Perl
Programs" for *Unix Review*, , and "Profiling
in Template Toolkit via Overriding" for *Linux Magazine*, .


The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in