--- "Chris \"Winston\" Litchfield" <[EMAIL PROTECTED]> wrote:
> Wow.. a simple thing turns into a boost of information.
[snip]
> The philosphy of performance improvement is introduced here.
> 1. Macros vs small Functions
This is fine, except that by using macros you make your code more difficult to
debug, because the source file that you are looking at isn't the same as the
one used to compile your code. (Once the preprocessor has changed everything).
This can cause some confusion for the debugger. But it will give you a slight
performance gain.
> 2. Switch Statements vs If, Then, Else trees
This will also give you a performance gain, though there are many instances
where you can't use a switch, since switches only work for the :
if(x==1){}
else if(x==2){}
type of if trees.
Changing to these will also give you only a minor performance increase.
(depending on how frequently the conditional is being evaluated).
> 3. single points of information (variable istead of multiple function calls)
This is ok, so long as you properly type them. For example, in your previous
performance tip you said to use an int. A const int, or better still a const
size_t, is actually going to work much better.
> small or not, its still an improvement..
Yes, but these will only give you a very small performance boost. Almost
negligable. And the time it takes to convert all your code as you suggest is
not really worth the effort IMO.
If you need to optimize, you should run the code through a profiler. Then when
you have a report telling you that most of your CPU time is spent in
update_handler or something, you take a look at what the code is doing and try
to make it more efficient.
I.E. Stop having it loop through every character_data in the game to see who is
fighting, or which mobs need to move this tick, etc. Create lists of these
character_data instances instead, to prevent looping over unimportant data. Or
create an event queue and store the fight and move events in there specifically
when something needs to fight or move. Then only search through those events ,
using an optimized search method, to find what you need to do. That sort of
thing will give you HUGE performance gains.
~Kender
=====
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/L/C/O d-(+) s++: a-- C+++$>++++ UBLS++++$
P+++(--)$ L+++>++++ E--- W+>++$ N !o K? w(--) !O
M- !V PS+ PE(++) Y+ PGP->+ t+ 5 X+() R(+) tv+@
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
------END GEEK CODE BLOCK------
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com