I've always wondered this. I have a habit of always adding
use strict;
use warnings;
use Data::Dumper;
to the top of every script I write. Does this add overhead if I don't even use the Dumper function? Also, in most cases Data::Dumper was called earlier in another package but I need it in this package so I include it again. In this case does it produce additional overhead?
If they have BEGIN
blocks or import
routines, then yes, it always adds overhead. Also any mainline code will be executed eventually and any INIT
, CHECK
, and END
blocks will also execute.
The only way it won't add overhead is if the module expects use
to be nothing more than like require
. (Of course, require
also runs everything except the import
routine, but that's why I mentioned the view from the use
-d module. It "expects" to be nothing but a simple require
.)
If you want to retain that line, for some reason, just comment it out. In development, it's okay to have modules that you don't use. In QA or production, that's a mistake, IMO.
Perl must parse the code in Dumper.pm
, so your program will be slower to start up. This is normally a very trivial hit to performance. Also, any code not in functions or in the import function will run. This may have a minor impact on your start up time. You will also consume more memory (the AST for the code and any data structures the code builds). It isn't the best thing you can do, but it is far from the worst. Unless your programs very often (multiple times a minute), you should not notice any real improvement in speed by removing the line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With