Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
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?
Solved! Go to Solution.
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.
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.
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
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.