Most Effecient way to repeat a handler/function - Found word(s) list error in the Text body
bobsneidar at iotecdigital.com
Fri Feb 14 03:53:53 CET 2014
Aye, but the question was which form of repeat was more efficient. In fact your example proves the point which is, it’s the actual code inside the repeat loop that takes way more time than the form of repeat itself.
What would really be of interest is comparing the form repeat for each word theWord of line x of tData to your example. So that is what I did:
put the ticks into line one of theTime
put "1 2 3 4 5 6 7 8 9 10" into tData
repeat with i = 1 to 100000
repeat with j = 1 to 10
get word j of tData
put the ticks into line 2 of theTime
repeat with i = 1 to 100000
repeat for each word theWord in tData
put the ticks into line 3 of theTime
put ("Example 1 took " & line 2 of theTime - line 1 of theTime) & " ticks" into line 4 of theTime
put ("Example 2 took " & line 3 of theTime - line 2 of theTime) & " ticks" into line 5 of theTime
Example 1 took 25 ticks
Example 2 took 12 ticks
That is fairly substantial. 25/60th of a SECOND to do 100,000 iterations on the SLOW loop! And the second form really gets the value twice, but still completes in 8 ticks. The repeat loop with nothing it it took just over 1 tick. That is damn fast in my book! Faster than I would have guessed, and much faster than I will ever need.
I suppose one could argue that some math calculations they can produce would dwarf my example, but then I would counter that just as LC is not a 3D graphics game development environment, so also it is not designed to produce lightning fast math apps.
I’ve likened LC to a constructor set approach to application building before. As in building a house, if someone wanted complete design freedom to make the house exactly as they desired, they would want to use raw materials (C++, Java etc) but if they want to throw a functional house together quickly so they can get on with building other houses, they should probably get as much pre made as they can and piece it together. That is LC to me, and thank Runrev for it let me tell you! :-)
On Feb 11, 2014, at 09:28 , J. Landman Gay <jacque at hyperactivesw.com> wrote:
> On 2/11/14, 9:48 AM, Bob Sneidar wrote:
>> For small tasks though, your users will not even be able to blink
>> before 100,000 simple repeats are executed. I ran a 100,000 count
>> loop with nothing in the repeat loop to do and it took 1 tick. ONE
>> TICK! The repeat loop is NOT what slows things down!
> Well, it depends. Try running your repeat loop with even a single line of code inside and use the form "repeat with x = 1 to 100000". That's the slowest way to do a repeat loop and I think you'll see a difference, particularly if the single line of code accesses any part of the current line. Every time through the loop, the engine has to count from 1 all over again.
> For example, try this and compare with your previous results:
> put my100000lineData into tData
> repeat with x = 1 to 100000
> get word 1 of line x of tData
> end repeat
> If you get word 10 of each line it will slow down more while the engine counts not only the line number but also the word number.
> Benchmarks would be interesting, if anyone has time to try it.
> Jacqueline Landman Gay | jacque at hyperactivesw.com
> HyperActive Software | http://www.hyperactivesw.com
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
More information about the use-livecode