We all know that using a module adds a little bit to the startup time of a Perl program, because the module has to be loaded and compiled on the fly (added: or linked, in the case of XS extensions). I was wondering exactly how much the cost for using a module is, so I ran some simple tests with a bunch of popular modules.

Basically, I timed how long does it take to run this program 11 times and took the average, discarding the first point because it usually takes longer than the other 10 due to caching:

perl -M$module -e1

The average times, in seconds (on a 2.8 GHz Pentium 4 with Linux), were:

diagnostics             0.100
Archive::Zip            0.092
Class::DBI              0.070
Archive::Tar            0.060
Template                0.036
YAML                    0.034
DBI                     0.034
Lingua::EN::Inflect     0.030
Math::Trig              0.023
CGI                     0.023
XML::SAX                0.020
XML::Simple             0.020
POSIX                   0.017
Data::Dumper            0.016
warnings                0.007
strict                  0.004

all of the above        0.390
none                    0.003

Note that the times are not additive: the sum for all the individual modules is 0.586 s, which is much larger than using all of them at the same time (0.390 s). I think this is partly due to the overhead of starting perl each time (which could account for about 0.045 s), but mostly because of common module dependencies.

To summarize:


In reply to Benchmarks for module compilation time by itub

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.