Tuesday, 20 November 2012

How to profile your perl script using nytprof

To figure out which part of your perl script is taking most of the time, you can "profile" your script.

I recently came across a blog by Jerome Quelin on how to profile your perl script using the nytprof profiler.

It's very easy to do this, you just type:
% perl -d:NYTProf script.pl
where script.pl is your perl script.

You then type:
 % nytprofhtml

This makes a directory called "nytprof" in which you will find a file "index.html".

If you look at the index.html file in a web browser, you will see a nice breakdown of which of how much time is spent in each subroutine of your perl script.

Here is what the output looks like, in this case the output for my perl script run_genewisedb_afterblast.pl:

In this case, it tells us that 146s of exclusive time was spent on system calls. We can click on 'CORE:system' in the first line to find where these system calls occurred in the code, and how much time each one took:


This is very handy for pinning down which bit of your code is taking up the most compute time, to help you think how you could speed it up.

No comments:

Post a Comment