Most Effecient way to repeat a handler/function - Found word(s) list error in the Text body
Peter M. Brigham
pmbrig at gmail.com
Mon Feb 17 17:17:33 EST 2014
Time test:
on testRepeat
put "xxx" into line 100000 of tList
replace cr with "xxx" & cr in tList
put the long seconds into timerStart
repeat with n = 1 to 100000
put line n of tList & cr after newList1
end repeat
put the long seconds into timerEnd
put timerEnd - timerStart into nEqualsTime
put the long seconds into timerStart
repeat for each line n in tList
put n & cr after newList2
end repeat
put the long seconds into timerEnd
put timerEnd - timerStart into forEachTime
put "n = 1 to 100000:" && nEqualsTime && "secs" & cr & "for each:" && forEachTime && "secs"
end testRepeat
produces:
n = 1 to 100000: 41.704915 secs
for each: 0.037602 secs
While replacing "put … after newList" with "put pi into y" in both repeat loops gives
n = 1 to 100000: 0.027132 secs
for each: 0.025698 secs
so it seems that the time-consuming thing is for the engine to retrieve "line n of tList" when n is large.
On Feb 17, 2014, at 4:50 PM, Peter Haworth wrote:
> Have to admit I'm the same. If it's more convenient codingwise to to
> repeat with x=1 to whatever and I know for sure there won;t be many
> iterations to go through, the speed difference is unnoticeable to the user.
>
> I'm also curious about another aspect of this. Is it universally true that
> "repeat with" is always slower than "repeat for" or only when the loop is
> addressing LC chunks of one sort or another?
>
>
> Pete
> lcSQL Software <http://www.lcsql.com>
> Home of lcStackBrowser <http://www.lcsql.com/lcstackbrowser.html> and
> SQLiteAdmin <http://www.lcsql.com/sqliteadmin.html>
>
>
> On Mon, Feb 17, 2014 at 12:39 PM, Peter M. Brigham <pmbrig at gmail.com> wrote:
>
>> On Feb 16, 2014, at 10:23 PM, Geoff Canyon wrote:
>>
>>> On Sun, Feb 16, 2014 at 2:52 PM, Bob Sneidar <
>> bobsneidar at iotecdigital.com>wrote:
>>>
>>>> Funny, just before I read your post I was thinking, "I wonder if this
>>>> scales linearly or logarithmically?" GET OUT OF MY HEAD!!! ;-)
>>>
>>> It's pretty much my personal quest to convince everyone never to use
>> repeat
>>> with i = 1 to the number of anything.
>>
>> Well, I still do it for i < 1000 or so, and the speed hit is perfectly
>> acceptable for that. The advantage for me is when I must use the number of
>> the iteration I'm in to do something. Sure I could do:
>>
>> put 0 into tCounter
>> repeat for each line LL in tList
>> add 1 to tCounter
>> ...< do things using tCounter here>...
>> end repeat
>>
>> but why bother for smaller sets of data?
>>
>> While we're dreaming of syntax extensions, how about this:
>>
>> repeat for each line LL in tList with counter = "tCounter"
>> -- the variable tCounter would automatically be initialized then
>> incremented with each iteration
>> ...< do things using tCounter here>...
>> end repeat
>>
>> -- Peter
>>
>> Peter M. Brigham
>> pmbrig at gmail.com
>> http://home.comcast.net/~pmbrig
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at 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 at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list