"Measure, dont't guess" is a main principle of performance optimization. So, if you see, that your scipt/application/whatever is running slow, you should profile it. Perl gives several good tools to do it, every perl programmer should know them
Devel::DProf is base profiler, and , by the way, in a week it will be the 10th anniversary of the release :)
you just run perl5 -d:DProf test.pl and get tmon.out file with raw profiling data.
Then you run dprofpp and see parsed data , something like this:
Total Elapsed Time = -0.03244 Secondsseeing top15 CPU consumers.
User+System Time = 0 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
0.00 0.090 0.090 30000 0.0000 0.0000 main::__ANON__
0.00 0.029 0.024 2730 0.0000 0.0000 Benchmark::new
0.00 0.010 0.020 3 0.0033 0.0065 main::BEGIN
0.00 0.010 0.010 5 0.0020 0.0019 Benchmark::BEGIN
0.00 0.004 0.048 6 0.0007 0.0080 Benchmark::runloop
0.00 - -0.000 1 - - vars::import
0.00 - -0.000 1 - - version::(cmp
0.00 - -0.000 1 - - Config::TIEHASH
0.00 - -0.000 1 - - Config::import
0.00 - -0.000 1 - - DynaLoader::dl_load_flags
0.00 - -0.000 1 - - DynaLoader::dl_load_file
0.00 - -0.000 1 - - DynaLoader::dl_undef_symbols
0.00 - -0.000 1 - - DynaLoader::dl_find_symbol
0.00 - -0.000 1 - - Time::HiRes::bootstrap
0.00 - -0.000 1 - - warnings::unimport
So, let's imagine,that you have found the subroutine, that consumes 50% of total CPU time .
But it is very long, so you should find an exact place to optimize...
use Devel::FastProf !
it is a line-by-line profiler. It dumps your code ,showing, how many times every line was ran , and how much time does it consume. All you have to do is optimize :)
and the third one is sexy Devel::NYTProf , all-in-one and even more
it produces accurate , detail results with minimum overhead, allowing to export data to html, csv and KCachegrid readable format, showing exclusive and inclusive time.
I prefere Devel::NYTprof, btw .
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=6c67db85-4343-4f75-953a-a63a940f71fd)
