Jadranko Stjepanovic wrote:
>
> Tony,
>
> I completely agree with your previous post.
> If we could calculate the total time spent on discussion about efficiency in
> this thread it would be surely huge compared to the performance difference
> between discussed functions. We should process vast number of
> points-on-lines in order to pay off such a bad investment of time.
> On the other hand, faster function is not the only gain of this discussion.
> I learned about undocumented sysvar "millisecs" (which I was completely
> unaware of) from two sides: You and R. Robert Bell.
>
> Anyway, risking the possibility to be called meticulous, I have to comment
> part of your previous post.
>
> You developed optimized version of point-on-line function and compared its
> results with previous functions:
>
> >
> >My results are as follows:
> >
> >Command: TEST
> >Points-on-line-1 (Tony): 2.3530
> >Points-on-line-2 (Jadranko): 1.3420
> >Points-on-line-3 (optimized): 0.4110
> >
>
> Furthermore you explained the performance difference by avoiding function
> call overhead:
>
> In my opinion, this statement could be misleading.
> The reason of such a big
> performance difference between optimized and non-optimized versions is not
> the pure function call overhead. Optimized version calculates multiple
> points on the same line, which allows the function to calculate all the line
> depending constants once for all the iterations, instead of calculating them
> again and again in each call of nonoptimized function. Efficiency increase
> caused by avoiding pure function call overhead is very very small compared
> to increase caused by avoiding recalculation of the same constants again and
> again.
You are right. The function call overhead is not entirely
responsible for the difference, as my original response
to your post with the improved version of (points-on-line)
clearly says:
> ......in a scenario where you
> would be calling the code many times, to find multiple
> points on the same line, the code should be optimized
> to eliminate all redundant expressions whose results
> are constant for the line (e.g., the distance between
> the endpoints and the delta).
> In other words optimized function took advantage of
> special case of multiple points on a single line.
This is not a 'special case', it is overwhelmingly the
most common case involving any iterative application
of this code.
> Similar optimization cannot be done in a more general
> (and not less probable)
I'm sorry, I don't agree with your characterization
of the 'multiple points on multiple lines at the same
or different distance' case as being more general and
'not less probable'. That is simply not the case. I've
used the optimized code I posted numerous times, to
find multiple points on the same line. On the other
hand, I've *never* had a scenario where I needed to
use the 'not less probable' case you cite.
In any case, even the highly-uncommon special case you
cite (many lines) can be optimzed further as well. For
example, if they are LINE entities, you can just use
(vlax-curve-getPointAtDist).
And, while we're discussing effeciency, I should also
note that using C++ would make the whole issue of
trying to optimize LISP code for this task, somewhat
moot. If optimization is *that* important, then you
should consider using C++ for the critical parts of
an application.
The basic point I was trying to make, was that there
was little benefit to optimizing the (point-on-line)
function I orignally posted, given the nature of its
parameters (which makes it completely inappropriate
for iterative use). And that optimization of any code,
has a lot to do with the context in which the code is
used, rather than a more general context typical of
a library function.
However, none of that was intended to belittle your
suggested improvement to the code.
Your point is well taken.
--
Checkout the AcadX(tm) ActiveX Extension Library at:
http://www.caddzone.com/acadx/acadx.htm
/*********************************************************/
/* Tony Tanzillo Design Automation Consulting */
/* Programming & Customization for AutoCAD & Compatibles */
/* ----------------------------------------------------- */
/* tony.tanzillo@worldnet.att.net */
/* http://www.caddzone.com */
/*********************************************************/