Code comments and execution time

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 :slight_smile:
  7. once studied and wrote a compiler using Prolog as part of my degree course :frowning:
  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:

Why?

times were 2.12 seconds vs 2.19 seconds

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. 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 :slight_smile:

Because that’s probably smaller than a disk block size, of which EVERY file is rounded up to in size when stored or read from on a disk… Which is why a hundred 256 byte files take 50k on a 512 byte per sector disk (FAT filesystem for example), 100k on a 1024 byte per sector disk (some *nix, kinda rare), and 200k on a 2048 or even 4096 bytes per sector disk (like most modern NTFS or NFS3 multi-TB drives). Ever notice that some programs report “file size” and “file size on disk” – and the latter is larger? Say hello to the smallest block size; which is the smallest a packet of data stored on a disk can be; most every filesystem out there does not support putting more than one file into a sector – since the hardware doesn’t support it either and you’d have to read, mask, and, and then write for those write operations.

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.

Ok, then the result was pretty good in your case

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.

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.

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 :slight_smile:

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.

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.

perfect way to make it obvious where something begins and ends.

The question appears again: Why isn’t it obvious in the first place? Or, why isn’t it obvious enough without
<?php /* ===================== START BLOCK ======================== */ ?>

Or

/**Header styles/
(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 */

some styles

/* 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.

Actually I find spaces around operators LESS clear because it then looks like a bunch of different operations instead of one… to me spaces are for around binary operators (and,or,xor,not) and not mathematical /syntatic/comparison ones. Basically I find:

$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?

^ this

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.

Really? I’m amazed. When I look at variables, operators, strings etc all cramped together into 1 bunch of characters, I find it hard to pick out out from the other. It all just looks like ‘a bunch of characters’ at a quick glance. Spaced out it’s a hell of a lot easier to see the separation between different types of characters - eg variables, lines, literal strings etc.

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!

I do indent properly, as I said above, and everything is on its own line as you say, but I wasn’t talking about matching one with the other - more that if you have some nested divs with some siblings around it etc, it can be harder to remember which one is the ‘block’ the comment refers to (block seems pretty meaningless as a description, but then out of context you have no idea what the page function is so could be perfectly meaningful in context).

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 do use that kind of thing for grouping styles (with 1 star though) eg:

I also do that kind of grouping, for when it’s stuff that doesn’t have any particular order in the HTML.

But I find the whole /ZOMG LOGOS*************/ thing a bit much. : )

I dunno, I can see how it makes sections very obvious - I have no particular problem with it, even if I don’t do it myself!

…and it’s certainly not a ‘FAIL HARD’!

NOOOOOO!!! That’s double the characters for every indented line you are going to crash the internet!

…No, but seriously - I thought most (if not all) code editors/IDEs allow you to set the tab indent?

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

The overall effect is to load the crappy, inefficient source code, javascript and images, in less than 2 seconds.

Mission accomplished :slight_smile: :slight_smile: :slight_smile:

Yeh, but then when someone uses a different one it can screw up the formatting in certain places.

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!

Well I guess that is a whole other debate - we probably don’t need another topic change in this thread so I will :x

Cheers

All the editors I use let you set the tab stop… I typically set it for two, but using tabs lets each person view it indented however much or how little they like.

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.

  1. 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.

  2. 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.

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.

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.

Notice Synopsis or scheme – like a “table of contents”? Those are indented on only one side. Parallel even though they can contain each-other.

I’m just glad PHP doesn’t care about your tabbing. That drove me insane when I was using Python.

That too.

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.