Thanks Hugh. I guess I'll be careful about where I use method 1 in future!
I would expect method 1 to take longer but that's a huge difference. I wonder if this would speed it up: Put the number of lines in tVar into tCount Repeat with x=tCount down to 1 Pete lcSQL Software On Aug 31, 2014 2:53 AM, "FlexibleLearning.com" <ad...@flexiblelearning.com> wrote: > Some benchtesting... > > Setup: > LC7DP10, Windows 7 > > Source data: > 10,000 lines of random data > 100 chars per line > 3,346 empty lines > > Task: > Strip lines where a given condition is met. > > Results: > Method 1 > Operating on a single variable, 'repeat with' + delete line > 25.586 secs > > Method 2 > Operating on a single variable, 'repeat for each' + filter with empty > 7.755 secs > > Method 3 > Using a second variable for output, 'repeat for each' + second variable > 0.136 secs > > Conclusions: > If memory is an issue, then Method 2 is best > If memory is not an issue, then Method 3 is best > > Scripts applied: > #1: > on mouseUp > set the cursor to watch > put the long seconds into tStart > put fld "Data" into tVar > repeat with x=the number of lines in tVar down to 1 > if line x of tVar="" then > delete line x of tVar > end if > end repeat > put tVar into fld "output" > put the long seconds - tStart into fld "timer1" > end mouseUp > > #2: > on mouseUp > set the cursor to watch > put the long seconds into tStart > put fld "data" into tVar > repeat for each line L in tVar > add 1 to x > if L="" then > put "" into line x of tVar > end if > end repeat > put tVar into fld "output" > put the long seconds - tStart into fld "timer2" > end mouseUp > > #3: > on mouseUp > set the cursor to watch > put fld "Data" into tVar > put the long seconds into tStart > repeat for each line L in tVar > if L<>"" then > put L &cr after stdout > end if > end repeat > if last char of stdout=cr then delete last char of stdout > put stdout into fld "output" > put the long seconds - tStart into fld "timer3" > end mouseUp > > > > On 30/08/2014 08:45, FlexibleLearning.com wrote: > > > Peter Haworth <p...@lcsql.com> wrote > > > > > >> There's another situation where I use repeat with even though it's a > little > > >> slower than repeat for and I also alter the contents of the data I'm > > >> repeating through without any problems. > > >> > > >> repeat with x=the number of lines in tVar down to to 1 > > >> if <data condition on line x of tVar> then > > >> delete line x of tVar > > >> end if > > >> end repeat > > > > > This is an insightful observation. Nice one, Pete! > > > > > > My stock method (and presumably the method you allude to above) is... > > > > > > repeat for each line L in tVar > > > add 1 to x > > > if <data condition on L> then put "" into line x of tVar > > > end repeat > > > filter tVar without empty > > > > > > Both methods operate on a single data set and avoid putting the output > > > into a second variable which, for large datasets, involve an > unnecessary > > > memory overhead.. > > > > > > Hugh Senior > > > FLCo > > > > _______________________________________________ > use-livecode mailing list > use-livecode@lists.runrev.com > Please visit this url to subscribe, unsubscribe and manage your > subscription preferences: > http://lists.runrev.com/mailman/listinfo/use-livecode > _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode