Tuple Performance

Are the following equivalent:

const (x, y) = (f(<parameter-list>), g(<parameter-list>));
const x = f(<parameter-list>), y = g(<parameter-list>);

Which is likely to be faster? ...Thanks

Hi Damian —

They act the same, yes. I'd be surprised if there was a very large
performance between them, if any, but if I had to pick a winner, I'd pick
the second form.

-Brad

Thanks.

I am trying to initialize variables in multiple directions, i.e. X, Y and Z.

There are identical variables in each directions. I have an inline routine which takes some input data in a given direction and returns a tuple of the initialized variables in that same direction. If using tuples to return data was impactful, I would have to replicate the code in each direction - which is pretty silly and goes against the whole concept of code reuse.

Thanks again.

As in ...

inline proc stagej(p, q, r, m, l)
{
    const c = (p - q) * ((p + q) + (m + m));
    const t = (p - m) + (q - m);

    return (m, t, c, (r - m) + (l - m), r + m, l + m);
}

used as

const (um, vxt, cxt, urld, urm, ulm, utt) = stagej
(   
    unip2[j], uni[j], unip1[jp1], unip1[j], unip1[jm1], uni[jp1]
);  
const (vm, vyt, cyt, vrld, vrm, vlm, vtt) = stagej
(   
    vni[jp2], vni[j], vnip1[jp1], vni[jp1], vnim1[jp1], vnip1[j]
); 

Hi Damian —

So, I would say that I wouldn't shy away from either of the two declaration forms on the basis of performance if it more naturally fits your computation. For example, in your original example, there's no real relationship between f() and g(), so it seems like a wash, and in the case of a wash, I'd avoid the tuples because they don't add value and may add overhead.

But in your most recent example, using the tuple unpacking seems beneficial to the code in terms of clarity, as does using just one subroutine call with multiple return values, so I'd take that approach. And I don't think the use of tuples should dramatically impact the performance (or, if it does, that's something we should look into improving if you could've written it out longhand and gotten better performance).

-Brad