"repeat for each" in reverse order ?

Dennis Brown see3d at writeme.com
Mon Jun 27 17:58:13 EDT 2005


Wouter,

I'm not sure what this example has to do with the question on the  
thread, but you first example is a speed killer.  Putting things in  
front of a string causes the whole string to be shuffled to make room  
for the inserted string.  It is a worst case situation --although I  
can always come up with a way to make it slower.  It would be faster  
to use the slower repeat for i=number of lines in x down to 1 and  
then put the lines after like your second example.

Splitting into an array is usually a good approach if the repeat for  
each construct will not work.  However, it does take time to do the  
split.  A repeat for each could process the whole string in less time  
than it takes to split it if a repeat for each fits the problem.

In your second example, sorting the keys will also take time.  You  
might be better off with just a simple repeat for i=number of lines  
in x down to 1 as the array index.  You would have to try it on your  
array to see.

Dennis


On Jun 27, 2005, at 4:24 PM, Wouter wrote:

> Hi,
>
> Using the following to reverse the order of lines of a field  
> containing 525605  chars in 14194 lines
>
>
> reversing by:
>
> on mouseUp
>   put fld 1 into x
>   put the long seconds into zap
>   repeat for each line i in x
>     put i&cr before tList
>   end repeat
>   put the long seconds - zap
>   put tList into fld 1
> end mouseUp
>
> takes > 60 seconds on a slowbook (G4 400 mhz)
>
>
> reversing by:
>
> on mouseUp
>   put fld 1 into x
>   put the long seconds into zap
>   split x by return
>   get the keys of x
>   sort it numeric descending
>   repeat for each line i in it
>     put x[i]&cr after tList
>   end repeat
>   put the long seconds - zap
>   put tList into fld 1
> end mouseUp
>
> yields around 0.413007 seconds on a slowbook (G4 400 mhz)
> (which is not too bad)
>
> The amount of chars and lines has a big influence on the speed in  
> the first handler,
> while in the second handler it has not.
>
> Greetings,
> Wouter
>
> On 27 Jun 2005, at 14:40, Dennis Brown wrote:
>
>
>> The repeat for each only goes in forward sequential order starting  
>> at the beginning, except for arrays where the order is indeterminate.
>>
>> I have requested a sequential access enhancement to allow for  
>> constructing this type of looping in a more flexible way (like  
>> parallel instantiation, starting at an arbitrary point, and  
>> reverse order), to make it possible to wander all over your data  
>> sequentially with the speed of the repeat for each method.   
>> However, it would be most useful with some improved string  
>> delimiter handling.  Bugzilla # 2773
>>
>> Having a reverse order repeat for each might be up to twice as  
>> slow as the forward version depending on how it is implemented,  
>> because it has to go backwards to the previous delimiter then  
>> forward to pick up the data, though it could pick up the data in  
>> reverse order on the way back.  However, even twice as slow would  
>> be much faster than any other method.
>>
>> Dennis
>>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>




More information about the use-livecode mailing list