Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Which is better - one large file or multiple files?

by Anonymous Monk
on Aug 09, 2001 at 18:53 UTC ( [id://103427]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I searched for an answer which I am sure is here somewhere, but came up empty.

I have a cgi that is getting large (greater than 100KB). Is it more efficient to have many small .cgi's called via "require" or better faster (less CPU) to have a single file?

Where is the cut-off for efficiency and how do you determine that cut-off?

Is there a way to measure and test efficiency?

Thanks!

  • Comment on Which is better - one large file or multiple files?

Replies are listed 'Best First'.
Re (tilly) 1: Which is better - one large file or multiple files?
by tilly (Archbishop) on Aug 09, 2001 at 19:27 UTC
    One file is always faster than many if you are loading the whole mess each time.

    Many files makes for cleaner development, and gives you the option of dividing one CGI into many, each of which loads far less data.

    My rule of thumb is that by the time it is big enough for the performance difference between one and many files to matter, the performance advantage of having many files so that you don't load it all at once wins. And if loading time is a problem, then you should probably be using mod_perl...

    UPDATE
    An incidental note. A vague memory is telling me that you might have issues with misplaced line-numbers if you have more than 64K lines in a single source file. That is another reason to use multiple files.

      Of course, if you're feeling daring, you can put your subroutine sub foo in a different file by saving it as foo.pl then, as and when your main script needs it, call it with
      do 'foo.pl';
      The disadvantage of this is that it doesn't get compiled unless and until you call it.
      The advantage is, it doesn't get compiled unless and until you call it.

      § George Sherston
        It is better to use Perl's AUTOLOAD for delayed loading. After all that is what it is for.

        If you just want to be able to take your program and force lazy loading of subroutines, you can use AutoLoader to do the loading and AutoSplit to split your file. That will perform much better on repeated calls to the function, and you can develop with a single huge file if you want.

Re: Which is better - one large file or multiple files?
by suaveant (Parson) on Aug 09, 2001 at 19:00 UTC
    It is often good to break up large files like that if many people work on it (so they don't overwrite each other)... also, if the code has a lot of branches, it may not be a bad to break it into pieces and only require the parts of code that you need when you need them... really we need more background on the cgi, what it does, how long it runs, etc to say for sure...

                    - Ant
                    - Some of my best work - Fish Dinner

Re: Which is better - one large file or multiple files?
by belize (Deacon) on Aug 09, 2001 at 18:57 UTC
    Forgot to login when posting above. Hmmm, another good question, how does someone attach their name to an Anonymous Monk post if you want answer to appear in the chatterbox (and to gain XP's form the post ;>)?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://103427]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-25 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found