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
https://forums.phpfreaks.com/topic/220363-class-autoload/
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
https://forums.phpfreaks.com/topic/220363-class-autoload/#findComment-1141880
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
https://forums.phpfreaks.com/topic/220363-class-autoload/#findComment-1141889
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.