empty program arguments do not need to be parsed
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 31 Oct 2022 19:53:24 +0000 (20:53 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 1 Nov 2022 03:14:54 +0000 (04:14 +0100)
Using Getopt::Long takes ~the same time as running the rest of the script,
about 250ms on a rpi1, so runtime can be halved if there's no options.

barcat

diff --git a/barcat b/barcat
index ab5c023398e94300363dfd1a23d991782b8d91e0..8e104c952713538e8dc7ad3d871a40012e4c00de 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -8,8 +8,10 @@ use re '/msx';
 
 our $VERSION = '1.07';
 
-use Getopt::Long '2.33', qw( :config gnu_getopt );
 my %opt;
+if (@ARGV) {
+require Getopt::Long;
+Getopt::Long->import('2.33', qw( :config gnu_getopt ));
 GetOptions(\%opt,
        'ascii|a!',
        'color|c!',
@@ -92,6 +94,7 @@ GetOptions(\%opt,
                );
        },
 ) or exit 64;  # EX_USAGE
+}
 
 $opt{width} ||= $ENV{COLUMNS} || qx(tput cols) || 80 unless $opt{spark};
 $opt{color} //= -t *STDOUT;  # enable on tty