[fpc-pascal] Speed

L L at z505.com
Wed Oct 31 00:43:49 CET 2007

>   I think first code is faster than second, because in first code
> SubCalculate function is in calling function body?

Actually some times local scope functions are slower because the variables need
to be carried around since you are doing somewhat of a lexical closure. The
local scope function can have hidden variables being passed in since it needs to
know about the parent function variables. So don't assume local scope is faster
always. Assume it is slower, but do testing to verify. It could even be faster
in some cases.. for example if you really do need to access all the variables in
one place.

> P.S. Where i can read tips about writing fast FP code?

I hear the Intel C compilers and Fortran compilers and Ada compilers are better
optimized for certain things since FPC/delphi are generally desinged for GUI
programming. ;-)

I've never had speed problems when I closely check my SetLength cals, Length()
calls on pchars. Too many class instantiations in a loop can slow down a bit, or
too many except calls in a loop.

Basically, optimizing Loops is the key always when it comes to performance.


More information about the fpc-pascal mailing list