Repeat loop optimization?

Glen Bojsza gbojsza at mac.com
Tue Mar 23 15:34:44 EST 2004


I tried the following experiment.

I have a field with 10000 lines and I want to convert the first word to 
seconds

Method 1

Break the 10000 lines into 5 separate loops. The start time and end 
time was recorded for each loop - ie when a loop completed the next 
loop started.

TIME TO PROCESS 21 seconds

Method 2 is the same script but with fire# commented out (firebig is 
the only loop)

TIME TO PROCESS 1 minute 27 seconds

This is a substantial difference...can anyone give me some pointers on 
how I should optimize repeat loops. I thought that doing the one big 
loop should be as fast as the multiple loops?

on mouseUp
fireUpdate
end mouseUp

on fireUpdate
   fire1
   fire2
   fire3
   fire4
   fire5
   --firebig
end fireUpdate

on fire1
   put long time into fld s1
   put line 1 to 2000 of fld "out" into ftemp1
   repeat with l = 1 to 2000
   get  word 1 of line l of ftemp1 && word 2 of line l of ftemp1
     convert it to seconds
     put it & cr after stime1
end repeat
put long time into fld e1
end fire1

on fire2
   put long time into fld s2
   put line 2001 to 4000 of fld "out" into ftemp2
   repeat with l = 1 to 2000
   get  word 1 of line l of ftemp && word 2 of line l of ftemp2
     convert it to seconds
     put it & cr after stime2
end repeat
put long time into fld e2
end fire2

on fire3
   put long time into fld s3
   put line 4001 to 6000 of fld "out" into ftemp3
   repeat with l = 1 to 2000
   get  word 1 of line l of ftemp1 && word 2 of line l of ftemp3
     convert it to seconds
     put it & cr after stime3
end repeat
put long time into fld e3
end fire3

on fire4
   put long time into fld s4
   put line 6001 to 8000 of fld "out" into ftemp4
   repeat with l = 1 to 2000
   get  word 1 of line l of ftemp1 && word 2 of line l of ftemp4
     convert it to seconds
     put it & cr after stime4
end repeat
put long time into fld e4
end fire4

on fire5
   put long time into fld s5
   put line 8001 to 10000 of fld "out" into ftemp5
   repeat with l = 1 to 2000
   get  word 1 of line l of ftemp1 && word 2 of line l of ftemp5
     convert it to seconds
     put it & cr after stime5
end repeat
put long time into fld e5
end fire5

on firebig
   put long time into fld sb1
   put line 1 to 10000 of fld "out" into fbtemp1
   repeat with l = 1 to 10000
   get  word 1 of line l of ftemp1 && word 2 of line l of fbtemp1
     convert it to seconds
     put it & cr after sbtime1
end repeat
put long time into fld eb1
end firebig




More information about the use-livecode mailing list