johnsmith153 Posted December 1, 2010 Share Posted December 1, 2010 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??? Quote Link to comment https://forums.phpfreaks.com/topic/220363-class-autoload/ Share on other sites More sharing options...
trq Posted December 1, 2010 Share Posted December 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/220363-class-autoload/#findComment-1141880 Share on other sites More sharing options...
requinix Posted December 1, 2010 Share Posted December 1, 2010 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... Quote Link to comment https://forums.phpfreaks.com/topic/220363-class-autoload/#findComment-1141889 Share on other sites More sharing options...
johnsmith153 Posted December 1, 2010 Author Share Posted December 1, 2010 Great. Thanks for help from all. Quote Link to comment https://forums.phpfreaks.com/topic/220363-class-autoload/#findComment-1141895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.