[thelist] efficiency/speed testing php

rytames at telusplanet.net rytames at telusplanet.net
Wed Jul 9 13:10:18 CDT 2003


On 8 Jul 2003 at 17:01, Chris W. Parker wrote:

> Hi.
[snip]
> I'd appreciate any help with this. i.e. techniques, code, links,
> advice, etc.

One of the most important aspect is to optimize loops. Keep in a
loop only what needs to be in it (i.e to perform the required 
algorythm). Sometimes 2 loops are faster then one, depending
on what is in the loop, and the function of the loop.

If using a compiler, use the optimization switches.

Reduce the usage of global variables to a minimum.

Sometimes certain operations can be used, and using them
reduces the CPU ops, from 3 instructions to one instruction (
i.e ++number, rather then number = number + 1 ).

Generally inline code is faster then using functions. However
functions are needed for extendability, and reusuable code; for
those certain functions that are in the need for speed, might want
to consider a macro instead.

Recursive functions are slow.

There are other things that are program dependant,  
for instance optimizing disk access (i.e. using what you know
to not search the entire data space ).

If using a OO language, might want to declare the variable
types before hand, and use those variables, only for the declared
type (i.e. i don't know, but it might help the interpeter to 
concentrate on running your code, and not running to parse the
variable typing).

In my opinion hungarian notation sucks, instead concentrate on
improving the code, rather then trying to improve the identifiers
( i.e. reduce the code base, and make it more extendable and 
expandable, which will make the code better, and more readable,
and easier to modify ), (i.e. if the code is spanning 13,000 lines, and
14 different files, I seriously doubt anything but well documented 
code will help ).

Use whitespace, and document your code, it will even give you
ideas on how to improve it. Also in my opinion use descriptive
names, but it need not have the variable type, nor the return type
in the name; Let the code documentation describe that stuff; Mind
you that is only my opinion, and has really, maybe not much to do
with optimization, except maybe it frees you up to begin changing
code, rather then just debating it, and seeing all the names that
have to be changed, and all the logic that needs to be redone
becouse you concetrated on "this _has_ to return this, and that 
_has_ to return that, this has to hold this type, oh uh, i better add
that in the name", if you understand where I am going with this,
great.

If not, I guess we all have our preferences, which I believe,
hunagrian notation somehow places limits, even if it is only
how you perceive the code; which in turn might limit how well
you code, and how well you describe your code, and I suppose
it limits how well you optimize your code.

Ryan.


More information about the thelist mailing list