homepage Welcome to WebmasterWorld Guest from 54.237.184.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Performance of "require"
Is the use of "require" includes a performance hit?
maximillianos




msg:3173754
 5:13 pm on Nov 30, 2006 (gmt 0)

Hello Everyone.

I'm working on tuning my scripts and was curious if anyone had any experience or thoughts on the use of "require" as it relates to performance.

Some of my more heavily used scripts have up to 10 require statements in them (including random .pl modules/code). Do these .pl includes get cached automatically by Apache? Should I have any concerns about the performance of using "require"?

Thanks for any advice.

 

perl_diver




msg:3173906
 7:01 pm on Nov 30, 2006 (gmt 0)

There are no performances issues that I am aware of. If you have seldom used modules you could load them conditionally only when they are needed:

if (condition) {require 'foo.pm'}

maximillianos




msg:3174039
 8:49 pm on Nov 30, 2006 (gmt 0)

Thanks for the reply. Most are required. I use them to help modularize my code. Not sure if that is the best approach... but that is what I've been doing... =)

phranque




msg:3174625
 9:37 am on Dec 1, 2006 (gmt 0)

if you have concerns about perl cgi script efficiency you should look into mod_perl.
(assuming apache here...)

rkrause




msg:3192292
 6:47 pm on Dec 18, 2006 (gmt 0)

Dear maximillianos:

Good question. For all practical purposes, the require statement is just an enhanced form of do that makes it possible to more effectively load libraries and modules. Further, the use statement is an enhanced form of require that makes it possible to more effectively import modules.

If you simply want to modularize your code and you are highly concerned about efficiency, you could theoretically use a do statement to achieve nearly the same result as require. I would advise reading the perldocs before doing so, as there are important distinctions nonetheless.

--Randall

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved