Fast/slow code example

Jon jbondy at sover.net
Fri Jun 24 08:31:35 EDT 2005


Eric:

Excellent contribution!

:)

Jon


Eric Chatonet wrote:

> Hi Christian,
>
> Le 24 juin 05 à 10:21, Langers Christian a écrit :
>
>> Could you, please, give us (newbies/intermediate scriptesr) some  
>> examples of fast/slow script code ?
>
>
> They would be too many :-)
> In fact, the problem is often more an architecture issue than a  
> simple code issue.
> But here is one tiny trivial example among thousands to give you some  
> clues:
>
> on CheckList
>   repeat with i = 1 to the number of lines of fld "List1"
>     set the itemDel to tab
>     put item 2 of line i of fld "List1" & cr after fld "List2"
>   end repeat
> end CheckList
>
> Main errors in the above 4 lines are:
> manipulate data directly from a field (a lot of work for the engine)
> use the "repeat with i" form slower than the "repeat for each" form  
> (especially noticeable with long lists)
> force a screen redraw at each repetition (that's the must for slowing  
> down)
> set the itemDel unnecessarily at each repetition
>
> The result with 1000 lines: more than 13 seconds...
>
> Better code:
>
> on CheckList
>   local tList, tLine, tNewList
>   -----
>   put fld "List1" into tList
>   set the itemDel to tab
>   repeat for each line tLine in tList
>     put item 2 of tLine & cr after tNewList
>   end repeat
>   put tNewList into fld "List2"
> end CheckList
>
> manipulate data into a variable
> use the "repeat for each" form
> use one screen redraw only
> set the itemDel only when needed
>
> The result with 1000 lines: less than 20 milliseconds!
> 650 times faster...
>
> Keep in mind that to answer correctly your request, this post should  
> be a 300 pages book :-)
> May be Dan wrote it?
>
> Best Regards from Paris,
>
> Eric Chatonet.
> ----------------------------------------------------------------
> So Smart Software
>
> For institutions, companies and associations
> Built-to-order applications: management, multimedia, internet, etc.
> Windows, Mac OS and Linux... With the French touch
>
> Free plugins and tutorials on my website
> ----------------------------------------------------------------
> Web site        http://www.sosmartsoftware.com/
> Email        eric.chatonet at sosmartsoftware.com/
> Phone        33 (0)1 43 31 77 62
> Mobile        33 (0)6 20 74 50 86
> ----------------------------------------------------------------
>
> _______________________________________________
> 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