I don't think PHP caches separate include files but every modern OS does so in the test there was actually no physical disk access. The .07 seconds was spent seeking those files by the OS in the memory. If you measured the time on first page load after system restart I believe the difference would be huge.It's possible PHP does an internal cache so it doesn't need to do a full read again.
Being the OP I thought it was time to clarify some issues:
1. the code snippet I posted was for demonstration purposes only
2. I am aware of bloated code especially for interpreted languages
3. I am aware of numerous performance issues relating to including files
4. would you believe I first programmed on punch cards early '70s last century
5. my first personal computer was a Tandy TRS80 with 4K of memory
6. 'have programmed using numerous languages including Assembler and used comments
7. once studied and wrote a compiler using Prolog as part of my degree course
8. using if(0) or if(1) is a simple way to toggle code snippets and monitor performance
9. actual performance results are not immediate due to reasons beyond my control
10. the site in question is used to test the latest evolving technologies
11. maybe one day I will be happy to finish and optimise the site
Meanwhile I get the general impression from the majority of posts in this thread that they are arguing over extremely small performance issues currently resolved by fast computers with an abundance of memory.
I am more concerned tracing bottlenecks between original source code and the final user output.
I am still looking for more suitable tools which will help in tracing bottlenecks.
Here is my task for today - courtesy of Google Webmaster Tools:
Also you guys are free to do your own tests and share your results
So for example on my machine (win7, NTFS, 4K blocks) a thousand quarter-k files would take two megabytes of disk space thanks to the block size (not counting the header blocks for sector tracking), while a 250k file would take 250k.
Like in *nix -- touch a file to make a new empty one -- congrats a zero byte file is now consuming an entire sector; typically 512, 1024 or 2048 bytes... OR MORE.
You are correct - I wasn't trying to argue that os caching is worse, although it may have sounded like that. Whatever mechanism does the caching it's good as long as it works.You may very well be correct, but if the os is caching the files, it's a moot point as the end result is still a negligible speed difference.
Actually, now I remember doing similar tests some 2-3 years ago on a few hosting servers I had access to and the conclusion was that the speed of include's was very dependent on the actual server. While separate includes suffered almost no penalty on one server they were pretty slow on another. The weird thing was that one server had eAccelerator installed and the includes were very slow. So there is no one answer to this since the speed depends on many factors and is very specific to a given setup.As has been mentioned several times in this thread, apc fixes any of these discrepancies anyway.
Also you guys are free to do your own tests and share your results
Been away for a day or so, but generally my point of view is that code should be clear, self documenting and readable. Given this, it amazes me that people don't do simple things like putting spaces around operators to make it far more readable (Something I think DS was against for some reason!), indenting and spacing things correctly (something I'm very fussy about) etc.
Also, it's my view that micro-optimisation is useless. And while I don't use the comments like START BLOCK myself, I can see how some people find them useful and have no problem with them, including with all the ******* or ===== to make them stand out - perfect way to make it obvious where something begins and ends.
I laugh at all the people who say you should use one style of echo, dots instead of commas, different quote styles etc because it is nanoseconds faster - completely silly given the grand scheme of things. Readability is THE most important thing in coding as far as I'm concerned.
The question appears again: Why isn't it obvious in the first place? Or, why isn't it obvious enough withoutperfect way to make it obvious where something begins and ends.
<?php /* ===================== START BLOCK ======================== */ ?>
(esp when followed by a bunch of stuff with "header" in the name)
The other question: WHO isn't it obvious to?
<div> doesn't really stand out of code that much - especially surrounded by lots of other divs, but that comment certainly does!
I do use that kind of thing for grouping styles (with 1 star though) eg:
/* Header */
/* Content */
Although it's obvious what styles follow it, it makes it a hell of a lot easier when scrolling around a css document to see the groups and find the one you are looking for.
$x=$x+1; clearer than $x = $x + 1;
Maybe it's just because symbols stand out like a sore thumb next to alpha for me -- maybe because I never saw ANYONE format code with all those extra spaces until about seven years ago... (which after 33 years of programming...)
But really that's a minor legibility issue and so long as the entire codebase is formatted CONSISTENTLY (pick a method and stick with it) I'm not THAT picky.
But in terms of DIV, it does stand out if you put your block level containers on their own lines and use the tab key -- the only reason for those type of giant comments with the endless strings of the same character is if you aren't indenting your code properly.
Is it that hard to look at the left edge of the screen and see the fist-in-the-face indent?
It's not an issue of how well the code is written, it's an issue of quickly being able to scroll through a giant file and quickly find a section that needs attention. This isn't a problem in a 200 line file, but a 2000+ line file (regardless of if your indenting/spacing is perfect) things are still hard to find quickly.
The days of trying to squeeze every byte out of the code to save space are gone. No need to be stuck in the old ways when there is a much easier way available now!
This is also a symptom of something I see a lot recently, that smaller / compact code means more efficient or neater code. It just isn't the case!
Even with the indenting, if the opening and closing are several screens apart, it can be harder to match them - although my editor highlights them anyway so not so much of a problem. I use a 2 space indent (tabs annoy the hell out of me) so everything doesn't go shooting off the right hand side of the screen once you've nested more than 3 levels deep.
I also do that kind of grouping, for when it's stuff that doesn't have any particular order in the HTML.I do use that kind of thing for grouping styles (with 1 star though) eg:
But I find the whole /**************************ZOMG LOGOS***************************************/ thing a bit much. : )
Has anyone taken the trouble to look at the source code generated for the home page of the relevant site?
According to the profiler the home page is generated is '0.0702secs'. Also numerous images are loaded using techniques gleaned from Speed Tips: Use Multiple SubDomains
Tabs were invented for layout out tabular data - ie, indenting several values to the same column no matter what the length of the previous column was. It was never supposed to be used for indenting.
The biggest risk is that if you allow tabs, you could have a mixture of tabs and spaces - which opens a whole can of worms in itself!
Though really spaces or tabs should make no difference as any editor worth using typically has a 'convert spaces to tabs' and 'convert tabs to spaces' and the really good ones have "convert leading spaces only to tabs" so switching back and forth between whatever you like and what someone else likes is easy. (I'll often hit the "convert to spaces" before posting code online if it's got a lot of indenting)
Though some editors don't do block indent/de-indent selection on spaces. (gEdit for example) many don't care what type of leading tabs are there when doing that (crimson, edit+, notepad++) -- though I'm often surprised how many programmers don't even know you can do block indent/de-indent.
Mostly I just find spaces instead of tabs annoying when making small edits or when posting code online - which is why I usually convert to tabs before editing and only convert to spaces for online posting of snippets.
Oh, and tabs were NOT invented for "tables" -- they were invented for indenting content and even for indenting the start of a paragraph; if you go back to typewritten age at least where you had mechanical adjustable tab-stops.
While tabulation is part of it's function, it's also for fixed indentations... like cleanly written code. In fact indent blocks could be considered tabular data since you are creating column indentations that line-up; since a table is NOT necessarily a grid.7. Also called tabulator. a stop on a typewriter, actuated by a key, that moves the carriage, typing element, etc., a predetermined number of spaces, used for typing material in columns, for fixed indentations, etc.
8. a programmed command on a computer, actuated by a key, that moves the cursor or printhead a predetermined number of spaces, used for keying material in columns, for fixed indentations, etc.
Notice Synopsis or scheme -- like a "table of contents"? Those are indented on only one side. Parallel even though they can contain each-other.an arrangement of words, numbers, or signs, or combinations of them, as in parallel columns, to exhibit a set of facts or relations in a definite, compact, and comprehensive form; a synopsis or scheme.
I'm just glad PHP doesn't care about your tabbing. That drove me insane when I was using Python.
I'm such a stickler for formatting you'd think I'd be a huge fan of python -- but the rest of that language which drove me nuts... (It's almost as needlessly cryptic as Ruby -- BAD when you have languages now that make C look verbose)
Well, that and I like to SEE the close on an element as an actual element and not JUST a de-indent. Gimme my RET, my LABEL, my }, my END; anyday over "I hit backspace"
See why I like 1TBS over Allman -- I like my close to line up with the statement being closed, not just the opening bracket.