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:
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.

-- 
Alexander S. Klenin
Insight Experts Ltd.

Attachment: double_const_benchmark.pp
Description: Binary data

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

Reply via email to