| Anders Andersson wrote:
> k1 = [blah]
> k2 = [blah]
> a1 oscil k1*k2-sin(k1),1,1
>
> Would it be faster to insert a k-rate variable to hold the calculation
> k1*k2-sin(k1)?
> k1 = [blah]
> k2 = [blah]
> k3 = k1*k2-sin(k1)
> a1 oscil k3,1,1
I haven't done any tests but logically I would imagine only if the same
calculation for a1 is to be repeated later for, say, a different f-table or
phase value, or, if k3 is used within another expression. Even then, I think
there would need to be many recalculations and k3 would have to be a fairly
complex expression (comprising higher order functions) for any detectable
difference to show up on modern computers.
> Or does CSound evaluate the expression in k-rate if it contains k-rate
> variables only?
>
> Example 2:
>
> kvol linseg 0, 1, p4/3, p3, p4/3, 1, 0
>
> Would this be slower than:
>
> itemp = p4/3
> kvol linseg 0, 1, itemp, p3, itemp, 1, 0
The latter would be faster because the calc p4/3 has to be done twice in the
former, and only once in the latter.
The real optimisation occurs less in the realm of machine speed and more in
the fact that if you decide to change the way you calc itemp, then you only
have to alter its definition once. The alternative is wading through the whole
instrument finding (and possibly missing) every instance of p4/3.
|