Perl/Profiling: Difference between revisions
From charlesreid1
(Created page with "TLDR: Use <code>Devel::NYTProf</code> =How to profile Perl= ==Before you begin== ===Installing cpanm=== Start by installing cpanm to take care of all your Perl packages:...") |
No edit summary |
||
| Line 62: | Line 62: | ||
Slide deck explaining a bit more about how to use NYTProf: www.slideshare.net/Tim.Bunce/develnytprof-200907 | Slide deck explaining a bit more about how to use NYTProf: www.slideshare.net/Tim.Bunce/develnytprof-200907 | ||
[[Category:Programming]] | |||
[[Category:N Queens]] | |||
[[Category:Perl]] | |||
[[Category:Profiling]] | |||
Revision as of 04:14, 19 March 2017
TLDR: Use Devel::NYTProf
How to profile Perl
Before you begin
Installing cpanm
Start by installing cpanm to take care of all your Perl packages:
brew install cpanm
Installing NYTProf
Install the best Perl profiling tool out there, the NYTProf, originally written by Adam Kaplan at the New York Times: https://www.perl.org/about/whitepapers/perl-profiling.html
cpanm Devel::NYTProf
This also installs the dependencies, of which there are multiple: https://metacpan.org/pod/Devel::NYTProf
Profiling Code using the NYTProf
Normally, we can time code using the time function, which gives a really high-level description of how long the code took to do stuff. Like, "this much user time, this much real wall time." Here's an example of output from the time command:
************************************** Running 8 queens problem with Perl... total 92 solutions real 0m0.112s user 0m0.025s sys 0m0.008s ************************************** Running 12 queens problem with Perl... total 14200 solutions real 0m11.726s user 0m11.519s sys 0m0.032s
We want to get a more detailed description of what's going on with the code to find bottlenecks.
Run a Perl script with the NYTProf module turned on:
perl -d:NYTProf myscript.pl
Resources
NYTProf
Official package info (some documentation, but nothing high-level at all): https://metacpan.org/pod/Devel::NYTProf
Slide deck explaining a bit more about how to use NYTProf: www.slideshare.net/Tim.Bunce/develnytprof-200907