[fpc-pascal] Program efficiency
Vojtěch Čihák
vojtech.cihak at atlas.cz
Wed Nov 9 14:43:04 CET 2022
Sorry, it was copy-paste from github and it broke formatting
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);
Or does it end up being the same when it's done?
I have a tendency to avoid using variables even though the code would be
infinitely more understandable if it was broken into sections and more
variables were used, but I'm wondering if this is really any more efficient
or if it just seems like it should be... after all storing things in a
variable and reading them out should take some time... but then again the
processor only works on one operation at a time anyway, so the final
assembly code would probably have to store things somewhere and get them
back... so.. is it really faster?
So if I never need the value a second time, is it really better to avoid
variables?
I could break it up an use comments:
O:= ((B+C/D)-E^F)+ //A
(H*(I+J))- //G
(L+M/N); //K
This got me thinking, it would be cool if there was some king of utility
that counted clock cycles for you while your program ran..and then I could
just try a sample program both ways and see what the results are...
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/a6605931/attachment-0001.htm>
More information about the fpc-pascal
mailing list