((lambda (x) (x x)) (lambda (x) (x x)))

Friday, November 14, 2008

Write Perl? You want this module.

The other day, I discovered a great, easy-to-use profiling tool that anyone who writes Perl is bound to love. The tool is called Devel::NYTProf, and you'd definately be doing yourself a favour by checking it out. It'll provide you with beautifully readable, comprehensive reports (in a variety of formats - I haven't tried them all yet, but so far I like HTML) on Perl programs of your choice, in which you'll find all sorts of useful information about what your program actually spends it's time doing.


To get ahold of it, just run the following command:

'perl -MCPAN -e 'install Devel::NYTProf''


To try it out on a Perl program of your own (let's say it's called 'example.pl'), just run...

'perl -d:NYTProf example.pl'


This will result in the creation of a file called 'nytprof.out' in your current directory. You can output a human readable HTML version of the report using a command like:

'nytprofhtml nytprof.out'


The 'nytprofhtml' command will have produced a directory called 'nytprof' in your current directory containing the report in an HTML format. You can open the report in your web browser of choice with the following command:

'xdg-open nytprof/index.html'


If you'd like to see an example of the sort of output it produces, you can check out the output it gave while profiling some of my code here:

'http://matrix.senecac.on.ca/~gjmasseau/nytprof-example/index.html'


From here, you can navigate through the report to view all sorts of useful information to help you optimize your program.


Until next we speak, happy profiling!

No comments: