Lately I've been thinking about how to speed up (GEOS) programs.
There are three possibilities:
1) Be faster.
Whatever your program is doing, do it faster. Choose better
algorithms, rearrange command sequencies. Save temporary results
from previous operations, unroll loops, combine small functions.
Remove code from your functions, even if it makes them harder to
read. Anything to lose just a few more CPU cycles. If necessary,
convert your (GOC) C code into assembly.
Always remember to add comments, they don't slow down the program,
but speed up the programming!
2) Be smarter.
Do only what is needed at the time it is needed. Sometimes it's
better to be prepared for everything, but usually it's faster to
check first, if something really has to be done.
If you need to zero an array of structures, don't set individual
values of individual items. Just set everything into zero at the
same time. If you need to reset nine values out of ten, save the
one unchanged, reset all, and restore the saved one.
3) Fool user.
Just make things look faster, even if your program would slow
down a bit. Difference is usually counted in (split) seconds,
so concentrate into speeding up the screen update. Calculate
first several items, then show all at the same time.
Move the slowness into another place. There are some things that
have to be done as fast as possible, other things that just have
to be done. Prepare for the fast actions, while you have time to
waste.
...
Why am I thinking this kind of things? There are a few programs
that should be made faster. The very first thing I would do, is
to run the programs through profiler and see what they are doing
and where they spend their time. The problem is that Geos does not
have a profiler.
I know of two kinds of profilers: one that counts the execution
time of something eg. functions and another type that counts how
many times a line of code has been executed.
Since swat is a line debugger, it should be easy to expand it to
behave as a line counting profiler.. Add an array sizeof number
of lines and change the swat so that when a line is entered, the
value in array is incremented. Then make it possible to change the
first column view in swat between line and profiler numbers.
I have two choices: I try to figure out how swat works, learn TCL
and write my own profiler in just a few months or make a few random
guesses and try my luck. I feel lucky today..
- --jouni miettunen