Algorithm time...
Richard Gaskin
ambassador at fourthworld.com
Sun Dec 9 04:49:13 EST 2012
Glen Bojsz wrote:
> Once again I hope the algorithm experts can speed of the following...
> currently on just 50,000 points it takes 10 seconds ...as I indicate
> below I know why so this is why I am looking for better solutions
...
>*on* mouseUp
> *put* the seconds into startTime
> *put* the number of lines of fld mydataNew into tcount
> *put* fld mydataNew into gbmem
> *put* tcount / 1000 into tgroup
> *put* 0 into x
> *put* 1 into y
> *repeat* for 1000 times
...
> *put* line startline to endline of gbmem into grptest
There are a few opportunities for optimization here, and if it had been
pasted as plain text so I could work with it without having to first
clean it up I might have done a quick rewrite.
But to get you started, the last two lines as excerpted above are important.
If you switch the repeat to use the "repeat for each line..." form
you'll get about an order of magnitude performance boost.
The issue is that "repeat <n>" doesn't know if the data being counted
may have changed, so when you later ask to go to line "startLine" each
time through the loop it starts counting at 1 and continues down to
startLine every iteration. This is a lot of redundant processing, and
as you can guess gets progressively slower as you work your way through
the data set.
The "repeat for each" form has the limitation that you cannot alter the
data being stepped through, but with that assumption is able to deliver
radically improved performance because it parses out the next line and
keeps its place in the data step each time through the loop, allowing
performance to scale linearly.
There are a few other things you might consider optimizing in that
handler, but once you get the switch to "repeat for each" worked out I
suspect you'll be so happy with the performance you'll move on to other
things. :)
--
Richard Gaskin
Fourth World Systems
Software Design and Development for Desktop, Mobile, and Web
____________________________________________________________
Ambassador at FourthWorld.com http://www.FourthWorld.com
More information about the use-livecode
mailing list