almr has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|