Welcome to WebmasterWorld Guest from 23.20.137.66

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Performance of "require"

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

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

WebmasterWorld Senior Member 10+ Year Member



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.

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

5+ Year Member



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'}

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

WebmasterWorld Senior Member 10+ Year Member



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... =)
9:37 am on Dec 1, 2006 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



if you have concerns about perl cgi script efficiency you should look into mod_perl.
(assuming apache here...)
6:47 pm on Dec 18, 2006 (gmt 0)

5+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month