Jump to content

Class Autoload


johnsmith153

Recommended Posts

Is using class autoload slower than including them yourself?

 

Should I include/require the class file and use class autoload as a backup in case I had forgotten, or can I just let class autoload load all the class files and never worry about including/requiring.

 

All classes are in the same directory and are always picked up - just want to know if it takes more time.

 

Is it much of a difference? Are we talking 1 or 2 milliseconds per request???

Link to comment
Share on other sites

If you only have a small library (and you mustif there all in one directory) then manual loading is fine. Autoloading only becomes more efficient when your library is bigger and objects start to require more dependencies. The best thing about autoloading is you only ever include what you actually use, this is mOre difficult to do manually.

Link to comment
Share on other sites

Is using class autoload slower than including them yourself?

Naturally. If you include it yourself that's one line of code. If you don't then a few more lines of code have to be executed... and then it gets included. More code means longer running time, but those microseconds lost are insignificant compared to the convenience you get with autoloading.

 

Note that the slowest part of autoloading is doing stuff on the hard drive. Like checking if a file exists. If you're scanning a dozen directories then it'll be noticeably slower.

 

Should I include/require the class file and use class autoload as a backup in case I had forgotten, or can I just let class autoload load all the class files and never worry about including/requiring.

Go for autoloading.

 

Is it much of a difference? Are we talking 1 or 2 milliseconds per request???

I would ballpark a guess at... less than half a millisecond? But it really, really depends: depends on the code, depends on the system, depends on the hard drive...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.