Eric,

For someone moving from other languages (like I am) to Transcript, I believe
three of the four errors you point out in your example should be obvious and
the same in all languages. Those are: 1. Repeatedly accessing the same data
structure (field) instead of first putting it into a variable. 2. Repeatedly
updating the screen on a background process. 3. Repeatedly setting a
property that only needs to be set once.

However, the "repeat with i =" form being slower than the "repeat for each"
was news to me!

There is nothing in the documentation, that I can find, that addresses the
most efficient way, from the perspective of the engine, to write a control
structure. Apparently, this is particularly true of the repeat structure. Is
it also true for say the if..then structure? Is it more efficient to put
your conditions into variables and then use the variables as conditions of
the if...then?

These are the kinds of things a newbie (like myself) would greatly
appreciate being documented. This is to say, if there are two or more ways
to write the same statement (as with the repeat example), then if someone
knows one works faster than the rest, because of their knowledge of the
inner workings of the engine, then this would be valuable to document or
post.

This might cut down the 300 pages. :)

Jim

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Eric
Chatonet
Sent: Thursday, June 23, 2005 11:02 PM
To: How to use Revolution
Subject: Fast/slow code example (was: Re: compileIt for revolution?)


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        [EMAIL PROTECTED]/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------

_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution



_______________________________________________
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution

Reply via email to