Yes, I always thought that "repeat with" was the only slow repeat method and as you point out it is only "repeat for each" that increases the speed not "repeat for".
Sorry about not pasting in plain text as I would have liked to have seen your solution. Glen On Dec 9, 2012, at 4:49 AM, Richard Gaskin <[email protected]> wrote: > 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 > ____________________________________________________________ > [email protected] http://www.FourthWorld.com > > > _______________________________________________ > use-livecode mailing list > [email protected] > Please visit this url to subscribe, unsubscribe and manage your subscription > preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode _______________________________________________ use-livecode mailing list [email protected] Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
