Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Compile Phase Time

by Coder1979 (Initiate)
on Apr 19, 2013 at 20:53 UTC ( #1029584=perlquestion: print w/replies, xml ) Need Help??
Coder1979 has asked for the wisdom of the Perl Monks concerning the following question:

After understanding that execution of a Perl program is divided into "Compile Phase" and "Run Phase" .. I am now trying to determine only the compile phase time of my perl program (especially of the packages I am including)
Here's a example if you are confused:
#!/usr/bin/perl use A; use B; use C; 1;
------------------------------ So what I want to know is From the moment i execute this program
how much time did it take to convert module A into optree, module B into optree and module C into optree.
I hope you guys get the vibe.

Replies are listed 'Best First'.
Re: Compile Phase Time
by LanX (Chancellor) on Apr 19, 2013 at 21:12 UTC
    I'd suggest you take a look at BEGIN, UNITCHECK, CHECK, INIT and END in perlmod and log the time of different phases.

    Cheers Rolf

    ( addicted to the Perl Programming Language)


    for more complicated checks I'd recommend using Devel::NYTProf

    (edit:link corrected)

      for more complicated checks I'd recommend using Devel::NYTProf

      check your links

Re: Compile Phase Time
by Laurent_R (Abbot) on Apr 19, 2013 at 22:30 UTC

    I am not sure of what you really need.

    But if you want to know the compile time, you could run the following type of command:

    $ time perl -c syntax OK real 0m0.313s user 0m0.077s sys 0m0.108s

    This gives you the time taken to compile, including any additional module used by

Re: Compile Phase Time
by Anonymous Monk on Apr 20, 2013 at 03:40 UTC


    #!/usr/bin/perl -- use strict; use warnings; use Module::Load ; use Time::HiRes qw/ time /; @ARGV or @ARGV = qw/ CGI B::Deparse DBI DBD::SQLite Moo Moose /; for my $mod( @ARGV ){ my $tb = time; load( $mod ); my $ta = time; printf "%.5f - %.5f = %.5f %s\n", $ta, $tb, $ta - $tb, $mod; } __END__ 1366428845.98106 - 1366428845.76563 = 0.21544 CGI 1366428846.11275 - 1366428845.98131 = 0.13144 B::Deparse 1366428846.15868 - 1366428846.11287 = 0.04581 DBI 1366428846.17056 - 1366428846.15895 = 0.01161 DBD::SQLite 1366428846.20396 - 1366428846.17067 = 0.03329 Moo 1366428846.71875 - 1366428846.20407 = 0.51468 Moose
      Will this approach underestimate load times for modules later in the list when they share dependencies with modules earlier in the list?

        Yes, but it doesn't really matter , whole exercise is silly. This version won't, but it will fail at loading Moose twice (or after moo)

        #!/usr/bin/perl -- use strict; use warnings; use Module::Load ; use Time::HiRes qw/ time /; @ARGV or @ARGV = qw/ CGI B::Deparse DBI DBD::SQLite Moose Moo /; for my $mod( @ARGV ){ my $tb = time; { local $SIG{__WARN__} = sub{}; undef %INC; load( $mod ); } my $ta = time; printf "%.5f - %.5f = %.5f %s\n", $ta, $tb, $ta - $tb, $mod; } __END__ $ perl fudge Moose Moo CGI CGI CGI CGI 1366466283.45313 - 1366466282.70313 = 0.75000 Moose 1366466283.52620 - 1366466283.45344 = 0.07276 Moo 1366466283.63069 - 1366466283.52631 = 0.10438 CGI 1366466283.73354 - 1366466283.63081 = 0.10273 CGI 1366466283.83594 - 1366466283.73366 = 0.10228 CGI 1366466283.93854 - 1366466283.83606 = 0.10247 CGI
Re: Compile Phase Time
by sundialsvc4 (Abbot) on Apr 23, 2013 at 01:09 UTC

    I confess that I am idly curious why you even care about the compile-phase time.   Slight variations in any observed metric are quite common.   Chalk it up to cosmic rays and sunspots.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1029584]
Front-paged by Corion
[Corion]: No, or I don't remember the story ;)
LanX my favourite don't tell me the proof of concept is good enough for production anecdote
[ambrus]: ah, it's one of thos
[Eily]: what, there's a difference between proof of concept and production?
[LanX]: 20 years ago traders were complaining about the latency of the trading system...
[ambrus]: I'm currently in the process of rewriting my proof of concept programs. They sort of developped organically as I was experimenting, so now I've got an ugly mess of multiple programs and one-liners held together by nothing. I'll have to rewrite them to som
[ambrus]: ething that's both cleanly organized and mostly automated.
LanX in train, bad connection
[Corion]: ambrus: Yeah - we're in that situation too, except that there is no time to do the reorganizing :-/

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (15)
As of 2017-03-29 11:47 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (350 votes). Check out past polls.