[std-interval] C++ interval std

Bill Clarke llib at computer.org
Wed Apr 5 17:27:51 PDT 2006


Alan Eliasen wrote, On 04/05/06 15:20:
> George Corliss wrote:
>>>Lawrence feels strongly that the standard should be to pass by
>>>value.  Intervals are small data structures; by value allows them
>>>to be passed in registers for speed.
[...]
>    I was curious to see about the speed difference between passing by
> value and passing by reference, because passing by value always has been
> slower and always *has* to be slower because it (unnecessarily) creates
> a copy of the object when passed in.  I tried three ways on x86_64, gcc
> 3.4.4, linux:
[...]
>    To the caller of the functions, it just looks like an ordinary
> pass-by-value, but is faster, and allows the compiler to catch a lot of
> types of problems.
> 
>    I recommend that for long-term performance and const-correctness,
> that objects be passed as constant references when possible.

This experiment is extremely platform specific, as you probably are
aware.  Most platforms in use today other than x86 will be the other way
around (add-by-value will be faster than add-by-const-ref).
(Was this 64-bit code?  I thought x86_64 would be faster with
pass-by-value since I got the impression the ABI passed parameters in
registers)

With inlining then they should be identical (perhaps you could re-run
your experiment with inlining to verify this?).

Surely it is possible to permit the implementer to choose the parameter
passing convention, between pass-by-value and pass-by-const-ref?  It
should have no visible impact on the programmer which is used.

e.g., within interval<T>:
typedef interval<T> param_type;
or
typedef const interval<T>& param_type;

cheers,
/lib
-- 
/lib BillClarke PostdoctoralFellow CompSci ANU cs.anu.edu.au/CC-NUMA
http://llib.cjb.net llib at computer.org  tel:+61-2-6125x5687 fax:x0010
PGPid:B381EE7DB7D3E58F17248C672E2DA124ADADF444 GNU unix LaTeX XPilot
Buffy DrWho Goodies StarTrek XFiles Origami SML SMP MPI mozilla tcsh
Asimov Bear Clarke Donaldson Volleyball Ultimate Cricket emacs C++ X
Jordan Kay Lackey Martin Stasheff DeepPurple H&C KLF Queen PinkFloyd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : http://compgeom.poly.edu/pipermail/std-interval/attachments/20060405/8c1bda12/signature.bin


More information about the Std-interval mailing list