On Sat, 2015-05-09 at 13:07 -0700, Walter Bright via Digitalmars-d wrote:
> On 5/9/2015 10:16 AM, Russel Winder via Digitalmars-d wrote:
> > Python has tuple assignment so you see things like:
> > 
> >          previous, current = current, previous + current
> > 
> > especially if you are doing silly things like calculating Fibonacci
> > Sequence values. Translating this to D, you end up with:
> > 
> >          TypeTuple!(current, next) = tuple(next , current +next);
> > 
> > I am assuming this is horrendously inefficient at run time 
> > compared to
> > having the intermediate value explicit:
> > 
> >          auto t = next;
> >          next = current + next;
> >          current = t;
> > 
> > or is it?
> 
> It probably depends on the compiler. The way to find out is to look 
> at the 
> generated assembler.

Using LDC, the tuple version generates more code unoptimized, but with
optimization, the exact same assembly language code is generated for
the two cases.

Win. 

Albeit the D syntax is not as nice as the Python syntax.


-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.win...@ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: rus...@winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to