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

What's a quick way to time how long it takes to compile a Perl module or program? (Preferably in a platform independent way.)

I seem to remember reading about this, but now can't remember where. Is there a module which does this? E.g.

perl -MDevel::CompileTime foo.pl

(Presumably, such a module could use BEGIN and CHECK blocks to time everything in between the first BEGIN and the last CHECK.)

What other approaches are there?

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re: How to measure compilation time?
by lima1 (Curate) on Jul 11, 2006 at 18:47 UTC
    no idea, but *lima1 wonders if he would make a serious mistake in just measuring
    sub { system('perl -c ' . shift) }
    with the Benchmark module*

    UPDATE: I thought you want to optimize compile time.

      That would work if I really wanted to establish it definitively over many iterations, but it also winds up including the system dispatch and perl's own startup time, which may or may not be relevant for a particular use-case.

      In this instance, I actually wanted it more in passing as I compile and run things during testing.

      As a side note, it's probably a bit more robust across platforms to do this:

      system( $^X, '-c', shift )

      Even more robust would be to use Probe::Perl instead of $^X.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Yes. You're also including a shell process and a new interpreter.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        You're also including a shell process
        Actually, you aren't, because the command does not contain shell meta characters (compare perldoc -f system). However I agree to xdg that the more-than-one-argument form of system would be better.