Wednesday, January 27
profiling perl
I wanted to profile a Perl script and get some idea if there were any absurd hotspots I could cut out. I googled “perl profiler” and hit on mention of Devel::NYTProf, which I vaguely remember but I’m not sure I’ve ever used.
Out of laziness, I installed by way of apt
instead of a CPAN client (I have
no idea which CPAN client you’re supposed to be using these days).
$ sudo apt install libdevel-nytprof-perl
It was a little harder to find a straightforward NOW DO THIS TO RUN IT
than I
wanted (I’d say I was about three glasses of wine in at this point), but after
the install I eventually landed on the following:
$ cd ~/code/projectroot
$ perl -d:NYTProf ./script_to_test.pl
$ nytprofhtml
After that, you can open ~/code/projectroot/nytprof/
in a browser. As an
example, my results for a recent test run (rendering this site, specifically)
are here. It’s not the least-inscrutable thing ever
written, but it didn’t take too long to figure out how to see the interesting
stuff. The HTML output is good enough that I didn’t feel any need to fire up
KCachegrind or anything, and I dig how it breaks down execution times
line-by-line.
Unsurprisingly, this is a Tim Bunce joint. That dude is a monster of practical utility.