Re: Optimizing the Speed / Design tradeoff in numeric applications





Jonathan Bartlett wrote:

The program took three points from n-dimensional space and did calculations to arrive at three values, named d2, t0 and theta. Each value is a function of the three points. However, many of the subcalculations for each value are shared.


So, the design side of me says that I should separate each calculation into it's own function/module, so that we have:

d2 = calc_d2(p1, p2, p3);
t0 = calc_t0(p1, p2, p3);
theta = calc_theta(p1, p2, p3);

What I like about this method is that it truly separates concerns.

Too far, perhaps. If you always calculate d2, t0 and theta together, then a transform function along the lines of


transform(p1, p2, p3, &d2, &t0, &theta);

is a perfectly workable solution; it's obvious in intent and can share common subcalculations.

Only if you want to calculate any one of d2, t0 and theta in isolation from the other two does it really make sense to have separate functions for each.
.




Relevant Pages

  • Re: Optimizing the Speed / Design tradeoff in numeric applications
    ... >> calculations to arrive at three values, named d2, t0 and theta. ... > I agree with Pete that whenever possible, design should trump ... My attitude would be to first separate the external world ... typedef struct gazouta { ...
    (comp.programming)
  • Re: Calculations Across Tables
    ... other calculations to leave them separate. ... For example, right now I have 5 separate queries, one for each table, ... because I'm pretty sure I'm capable of handling those ... Do you have any suggestions for my original question? ...
    (microsoft.public.access.queries)
  • Re: Question on types conversions - operations
    ... there are far more enumerations than reals, and very few calculations. ... Also, we tend to have coordinates or (r, theta) so it's a lot ...
    (comp.lang.ada)
  • Re: printf ultra-fast question
    ... Aah, stupid mistake. ... theta was double, so the following works: ... That explains the strange behaviour from vs2005... ... separate argument, rather than the simpler: ...
    (comp.lang.c)
  • Re: Vector Question
    ... >> I do not seem to recall from Physics on how to do this. ... >>to calculate a vector between these two, and then add a varing angle, ... >>say theta, to the result so that I can perform some calculations. ...
    (sci.math)

Loading