# [fpc-pascal] Program efficiency

Vojtěch Čihák vojtech.cihak at atlas.cz
Wed Nov 9 14:40:17 CET 2022

```Hi,

I noticed this too a few years ago when I translated xxHash from C to FPC.
Pushing the code to less lines improved speed so xxHash32 was as fast as in C.

do { v1 = XXH32_round(v1, XXH_get32bits(input)); input += 4; v2 = XXH32_round(v2, XXH_get32bits(input)); input += 4; v3 = XXH32_round(v3, XXH_get32bits(input)); input += 4; v4 = XXH32_round(v4, XXH_get32bits(input)); input += 4; } while (input < limit);

repeat
v1 := cPrime32x1 * RolDWord(v1 + cPrime32x2 * PLongWord(ABuffer)^, 13);
v2 := cPrime32x1 * RolDWord(v2 + cPrime32x2 * PLongWord(ABuffer+4)^, 13);
v3 := cPrime32x1 * RolDWord(v3 + cPrime32x2 * PLongWord(ABuffer+8)^, 13);
v4 := cPrime32x1 * RolDWord(v4 + cPrime32x2 * PLongWord(ABuffer+12)^, 13);
inc(ABuffer, 16);
until not (ABuffer <= pLimit);

______________________________________________________________
> Od: "James Richters via fpc-pascal" <fpc-pascal at lists.freepascal.org>
> Komu: "'FPC-Pascal users discussions'" <fpc-pascal at lists.freepascal.org>
> Datum: 09.11.2022 13:47
> Předmět: [fpc-pascal] Program efficiency
>
I was wondering if breaking up large complicated formulas into smaller
sections that use more variables is less efficient than just the large
formula.

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);

James

_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal <https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal>

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