Devel::DProf - Simple Profiler
You may not get the performance you want when you run the program. Finding out which part is the bottleneck is not easy. You can use a tool called a profiler to find out which process in your program is taking a long time. (Currently, it is better to use Devel::NYTProf.)
The standard module has a simple profiler, the Devel::DProf module , which you can take advantage of.
Creating a profile is easy. When the following command is executed, a file that outputs the profile information "tmon.out" is created in the current directory.
# Create profile information perl -d: DProf target.pl
To display "tmon.out" in an easy-to-read format, execute the dprofpp command.
# Display profile in easy-to-read format dprofpp
Then, it will be output in the following easy-to-read format.
# Profile Total Elapsed Time = 1.171916 Seconds User + System Time = 1.171916 Seconds Exclusive Times # %Time ExclSec CumulS Calls sec/call Csec/c Name 78.6 0.922 0.922 2 0.4610 0.4610 main::func2 18.6 0.218 0.218 1 0.2180 0.2180 main::func1 1.37 0.016 0.016 5 0.0032 0.0032 main::BEGIN 0.00 - - 0.000 1 - -- strict::bits 0.00 - - 0.000 2 - -- strict::import 0.00 - - 0.000 2 - -- warnings::import
The meaning of each item is as follows. It is displayed from the top in the order of time.
%Time | Percentage of subroutine execution time to total |
ExclSec | Subroutine execution time(not including subroutine calls) |
CumulS | Subroutine execution time(including subroutine call) |
# Calls | Routine call count |
sec/call | Subroutine execution time per subroutine (excluding subroutine calls) |
Csec/c | Subroutine execution time per subroutine (including subroutine call) |
Name | Subroutine name |
The above result is the result in my environment when I run the script.
use strict; use warnings; func1 (); func2 (); func2 (); sub func1 { my $i = 0; while ($i < 1000000) { $i++; } } sub func2 { my $i = 0; while ($i < 2000000) { $i++; } }
The number is incremented using while statement.