[fpc-pascal] Program efficiency

Sven Barth pascaldragon at googlemail.com
Wed Nov 9 14:08:03 CET 2022

James Richters via fpc-pascal <fpc-pascal at lists.freepascal.org> schrieb am
Mi., 9. Nov. 2022, 13:47:

> In other words.. is
> A:=(B+C/D)-E^F;
> G:=H*(I+J);
> K:=L+M/N;
> O:= A+G-K;
> Less efficient than
> O:= ((B+C/D)-E^F)+ (H*(I+J))-(L+M/N);
> Or does it end up being the same when it's done?

The compiler will insert temporary variables anyway when necessary (so even
your first example might infact contain more variables and your second will
very likely contain temporaries).
Using optimizations (especially regvars, used by default in -O2) might
improve this independent of whether you use variables yourself or not.

But in general: you should look at other things to optimize and only come
back to this when you have nothing easier to improve.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20221109/9cdc99e8/attachment.htm>

More information about the fpc-pascal mailing list