I've been working on a "quick and dirty" script that should run from .bashrc. It seemed a lot slower than an equivalent bash script (which runs several executables...), so I decided to time it. It turned out the code itself didn't really make a difference -- it was the imports that were sluggish.

In particular, just importing (without using at all) autodie, Pod::Usage and Getopt::Long will slow down a do-nothing program. Here are the results from hyperfine (-adie means enable autodie, -podu = Pod::Usage, and -go = Getopt::Long; actual programs at the end)

Benchmark 1: /tmp/x-go-adie-podu.pl Time (mean ± s): 107.1 ms ± 0.5 ms [User: 94.5 ms, Sys: 12.5 ms] Range (min … max): 106.2 ms … 108.1 ms 27 runs Benchmark 2: /tmp/x-go-adie.pl Time (mean ± s): 50.2 ms ± 0.2 ms [User: 44.5 ms, Sys: 5.7 ms] Range (min … max): 49.7 ms … 50.6 ms 58 runs Benchmark 3: /tmp/x-go.pl Time (mean ± s): 25.7 ms ± 0.1 ms [User: 21.6 ms, Sys: 4.1 ms] Range (min … max): 25.5 ms … 25.9 ms 112 runs Benchmark 4: /tmp/x.pl Time (mean ± s): 7.8 ms ± 0.1 ms [User: 5.3 ms, Sys: 2.5 ms] Range (min … max): 7.6 ms … 8.1 ms 324 runs

So, we jump from 8ms to 25ms to 50ms to 107ms just by importing (in order) Getopt::Long, autodie, and Pod::Usage. Once it reaches tenths-of-a-second territory I get itchy, because it's starting to become visible to humans.

Anyway


Actual files:

### /tmp/x-go-adie-podu.pl #!/usr/bin/env perl use strict; use warnings; use Getopt::Long qw( :config ); use Pod::Usage; use autodie; ### /tmp/x-go-adie.pl #!/usr/bin/env perl use strict; use warnings; use Getopt::Long qw( :config ); use autodie; ### /tmp/x-go.pl #!/usr/bin/env perl use strict; use warnings; use Getopt::Long qw( :config ); ### /tmp/x.pl #!/usr/bin/env perl use strict; use warnings;

In reply to slow startup for some common modules? (autodie, Pod::Usage, Getopt::Long)) by almr

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.