Alexander Klenin schrieb:
On Mon, Nov 17, 2008 at 05:39, Florian Klaempfl <[EMAIL PROTECTED]> wrote:
No, just look at the actual assignment:
i:=v;
By const/reference it generates 5 instructions, by value only 4. The rest is
entry code. If you've only one access, passing by reference might have an
advantage, the more accesses you have, the better direct passing is.

This is true only if the code is compiled without optimization. At -O2 level,
the access code is indeed identical from performace POV.

Just benchmark a loop ;)
I did, see attachment. On the random old PC it gives me:

Yes, the compiler can hide in the this case the additional load because the procedure is very simple. Also alignment is part of the game, but the main point is that in the ref. case the compiler can use a stack pointer based stack while in the other case it needs a frame pointer based stack.

It simply depends on the procedure code (and the architecture!) what's faster

By val = 1.47s
By ref = 0.72s

By increasing the value of NR constant, you can diminish speed difference,
but the by-ref case is always faster.

Anyway, for me the true reason for always using by-ref convention for
const parameters
is semantic consistency and Delphi compatibility.



------------------------------------------------------------------------

_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel

_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to