gam3 has asked for the wisdom of the Perl Monks concerning the following question:

I have a program that takes a very long time to load.
I am sure that it is one of the packages that I am useing. Does anyone know of a way to figure out which package is taking a long to load?
I would hate to have to comment them out one by one.
-- gam3
A picture is worth a thousand words, but takes 200K.

Replies are listed 'Best First'.
Re: Timing Compile time, or timing 'use'.
by ikegami (Patriarch) on Jan 30, 2007 at 00:01 UTC
    To time use, just put BEGIN blocks between the use statements.
    BEGIN { ...1... } use ModuleA; BEGIN { ...2... } use ModuleB; BEGIN { ...3... } use ModuleC; BEGIN { ...4... }

    The above code will get executed in the following order:

    ...1... require ModuleA; import ModuleA; ...2... require ModuleB; import ModuleB; ...3... require ModuleC; import ModuleC; ...4...
Re: Timing Compile time, or timing 'use'.
by BrowserUk (Patriarch) on Jan 30, 2007 at 04:57 UTC

      When debugging some dynamic loading and fighting UNIVERSAL::require, I found the following very helpful to have at the end of every package:

      warn __PACKAGE__ . " loaded\n";

      which should be combined with your approach to give the timestamps too.

      Another approach might be to load a coderef into @INC that turns around and loads all modules while outputting timing information:

      perl -MDevel::TimeLoad myprogram.pl

      ... but I don't have the time to implement a prototype for that.

        There are several packages on my system that have a warn __PACKAGE__; at the end as a result of my trying debug some problem or other. Every now and again I'll use one, see the output and get around to removing it.

        I really like your Devel::TimeLoad idea. There are many occasions when such a beast would have be very useful. I've seen references to 'coderefs in @INC' float by over the last year or so, but I've never had occasion to go read up about them. Indeed, off the top of my head I don't know where to look, but I'll find it.

        Someone will probably beat me to the punch, but if there isn't such a module on cpan by the time I've worked out how/what to do, I'll put my efforts up there.

        I'd also like to write a -MO style shortcut for Devel modules to facilitate their use from the command line, but of the top of my head I haven't a clue if that's possible?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.