cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Is there an explanation for that huge speed difference?

Werner_E
24-Ruby V

Is there an explanation for that huge speed difference?

Attached find a worksheet with three different routines to draw a circular frame around an RGB image.

I have no explanation why the second and third routine are over 100 times slower than the first, which uses an auxiliary routine which is called three times.

I would have expected FrameImg2 to be a bit more speedy than the other two because the if condition is only evaluated once and the i-loop is only triggered when necessary.

Anybody an explanation?

FrameImg.png

1 ACCEPTED SOLUTION

Accepted Solutions
RichardJ
19-Tanzanite
(To:Werner_E)

Because in 2 and 3 when you loop through all the rows and columns you are indexing into a nested array every time. It is much faster to split out the 2D array three times and just index into those arrays.

View solution in original post

5 REPLIES 5

I don't know why there is green area below in the Img2.

zhu laojianke wrote:

I don't know why there is green area below in the Img2.

Right Click/Properties/Highlight Region/Choose Color and choosing the same color as was the second parameter given to FrameImg1/2/3.

RichardJ
19-Tanzanite
(To:Werner_E)

Because in 2 and 3 when you loop through all the rows and columns you are indexing into a nested array every time. It is much faster to split out the 2D array three times and just index into those arrays.

Thanks for your explanation, Richard.

Is there any reason known, why indexing a nested array is sooo much slower? I can't think of one other than Mathcad maybe copies the indexed array to change a single value and copy it back afterwards, which would be a really unnecessary awkward way to implement that feature.

But I guess as we don't have access to the source code we can only accept things as they are. Similarily the incomprehensible effect that stack and augment are much slower than self written routines using nested for loops, as it was discussed in a former thread.

Thanks again for your help!

Werner

RichardJ
19-Tanzanite
(To:Werner_E)

It doesn't make much sense to me either. But, as you say, we have no way to know how it is implemented in the bowels of Mathcad.

Top Tags