Perl: How to profile Perl code to improve your code quality

If you've written some Perl and you want to improve upon the execution speed you can use a profiler. There are several profilers available, but the best one I've found is Devel::NYTProf. Once you have the module installed you run your Perl script as normal but invoke the profiler:

perl -d:NYTProf term-colors.pl

This will result in a nytprof.out file being created in the current directory. This file contains raw stats about function calls and code timings. You can turn this data into something human readable by converting it to HTML.

nytprofhtml nytprof.out --out perl-profile/

This will create a nice HTML page with all kinds of information about how the Perl interpreter ran your script. With this information hopefully you can find places in your code that could use improvement.



Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 100.26.196.222
To prevent spam please submit by clicking the kitten: