My browser game is progressing steadily, mainly thanks a lot of information I got from these forums=)
I have a question about performance, which is;
Does the INCLUDE command have a big impact on performance?
While I was working on my game, at one point I wanted to have a bit more structure in my php files. So for readabilty I created a bunch of seperate PHP files (mainly code being used in multiple places, or standalone functionality) and also create some subfolders to put them in.
So now my main PHPs have a lot of INCLUDEs.
First I left all the new created INCLUDE PHPs in the same root dir, and when testing it didnt seem to have a big impact on performance. But on 1 pc its kinda hard to stress-test it.
When I placed the PHP's in seperate subfolders (for example a combat folder, a statinfo folder, etc. etc. Each with a few PHP's on that subject), performance did seem to take a hit.
I used the following notation to direct to the PHP's.
For INCLUDES called from a PHP in the root dir I did:
include 'hero/heroraceclassinfo.php';
FOR INCLUDES called from a PHP in a subfolder I did:
include '../hero/heroinfo.php';
Now Im wondering if I should change it back to all PHP's just in the root folder. Or maybe somebody can enlighten me a little on the use of Includes?
Thanks in advance=)
Performance
- hallsofvallhalla
- Site Admin
- Posts: 12026
- Joined: Wed Apr 22, 2009 11:29 pm
Re: Performance
you will not see any difference. Browsers can run thousands upon thousands of lines of codes in milliseconds. I use to worry about includes and libraries but soon learned that a 200x200 image not properly saved in the right format can cause more of a hang up than 10 include files with 500 lines of code each.
Re: Performance
It doesn`t matter at all. Including means you only set a new file pointer to require lines of code. It`s all happening on the server, so no harm is done. My latest "framework" is including ( i use require.. ) about 40 files. Average load is somewhere between 0.0003 and 0.0010 seconds. The browser is the bottleneck for having to display the page, which takes up about 90% of the time on every page load.
Oh, and if you`re smart, use the require_once or include_once files. That way, pages are stored in cache and anytime later on in your script you accidentally want to include it, it will load the cache file. Since cache is allways faster then going back to hdd and retrieve it, it`s a a huge speedboost for a computer. Mostly because cpu`s think HDD`s are way slow. We won`t notice any difference, but then again, we cannot perform 10^15 operations a second
Oh, and if you`re smart, use the require_once or include_once files. That way, pages are stored in cache and anytime later on in your script you accidentally want to include it, it will load the cache file. Since cache is allways faster then going back to hdd and retrieve it, it`s a a huge speedboost for a computer. Mostly because cpu`s think HDD`s are way slow. We won`t notice any difference, but then again, we cannot perform 10^15 operations a second
Re: Performance
Thanks a ton for the quick replies. Indie-Resource.com rules=) Ive learned so much from the few weeks im lurking on these forums. Google can be your best friend, but sometimes 1 decent resource is 100x better =)
Anyway, Im glad I dont have to worry about performance when using includes from other folders. I always like to keep my projects very structured right from the start , so I dont have to clean up the mess later in the project =)
Anyway, Im glad I dont have to worry about performance when using includes from other folders. I always like to keep my projects very structured right from the start , so I dont have to clean up the mess later in the project =)
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: Performance
I definitely second to use include_once(). While Includes really won't slow anything down in the long-run (like was said, the browser is really the culprit in page loads, particularly with people still using old IE versions with their dreadfully slow JS interpreter), loading an already loaded version of your script from memory would be orders of magnitude faster than opening a file. Again, while it is minuscule (maybe a couple of milliseconds), opening files is quite slow in computer terms. You would only see a real difference if your server starts getting bogged down with thousands and thousands of hits an hour, but you may as well design your code to accommodate being that popular now, right? Sometimes the floodgates open while we are sleeping, so it helps to be prepared 
The indelible lord of tl;dr