Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

use and performance

by mce (Curate)
on Jun 10, 2003 at 10:11 UTC ( #264605=perlquestion: print w/replies, xml ) Need Help??
mce has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have a OO framework of several modules, and dozens of programs that make use of these modules. In each module I always start with the same lines.

use strict; use Data::Dumper; use Carp;
My question is, is it really needed to import Data::Dumper and Carp in every package file?
Does it have a noticable performance impact?

If it is use'd once (f.e. in my constructor class, which is called by every program in its ISA structure), I should be able to call Dumper by referring to Data::Dumper::Dumper,isn't it.

What is the best practice for this?

I have (not yet) any long running daemon.

I hope this question is clear enough.
---------------------------
Dr. Mark Ceulemans
Senior Consultant
BMC, Belgium

Replies are listed 'Best First'.
Re: use and performance
by diotalevi (Canon) on Jun 10, 2003 at 10:28 UTC

    There is no execution speed impact - loading the code and calling Data::Dumper->import(), Carp->import in multiple locations at compile-time has no runtime implications. By importing the Dumper(), carp(), confess(), etc functions into multiple namespaces you may be occupying more memory than necessary but that doesn't mean it is slower.

Re: use and performance
by perrin (Chancellor) on Jun 10, 2003 at 14:55 UTC
    The best practice is to use all the modules you need in every module that needs them. There is no speed issue (perl only loads them the first time) and it serves as useful documentation.
      This isn't entirely true, since all those imports can really kill your script's startup time. If startup time's an issue, you should "use" modules only once, and just "require" them everywhere else. Equally good documentation, but less pain.

      /s

        I shudder to think how many imports it would take to make a dent in the startup time of a script on a modern computer. Most imports don't do anything at all.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://264605]
Approved by valdez
help
Chatterbox?
[msh210]: I don't have sendmail (I'm on MS Windows), so does one of you think you can report the bug?
[shmem]: msh210: 'tis about time to tell the sad truth to perl5porters - via perlbug
[msh210]: probably whoever wrote that actually knows the truth
[shmem]: msh210: you can save the perlbug text in a file and send that via your mail agent of choice
[msh210]: hm, okay, I'll try, thanks
[shmem]: ...not as an attachment, it's probably better to c&p that into the mail body

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2017-04-24 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (439 votes). Check out past polls.