Re: Strings & Loops
Re: Strings & Loops
- Subject: Re: Strings & Loops
- From: Thomas Fischer <email@hidden>
- Date: Mon, 06 Feb 2012 10:36:59 +0100
Hello Nigel,
thanks for the comprehensive answer!
Sorry this is somewhat belated, I was busy.
Am 02.02.2012 um 02:13 schrieb Nigel Garvey:
> KOENIG Yvan wrote on Wed, 01 Feb 2012 11:43:22 +0100:
>
>> Le 1 févr. 2012 à 11:11, Thomas Fischer a écrit :
>
> [snip]
>>> Case 3:
>>> set outText to {}
>>> set outTextRef to a reference to outText
>>> set myTimer to start timer
>>> set theChars to every character in inText
>>> set theCharsRef to a reference to theChars
>>> # repeat with aChar in text of inText # <- Not only much slower (~40x),
>>> but results often(?) incomplete!
>>> repeat with aChar in theChars # Ref # <- Here Ref is actually slower (~2x)!
>>> copy aChar to the end of outTextRef # <- without Ref much slower (~15x)
>>> end repeat
>>> set outText to contents of outText as text
>>> set myTime to stop timer myTimer
>>> log outText
>>> myTime
>>>
>>> Ergebnis:
>>> 47.761962890625
>>
>> This behavior was described for the first time several years ago by
>> Serge Belleudy-d’Espinose.
>>
>> It's described in Matt Neuburg's AppleScript The Definite Guide.
>
> The speeding-up of list access through the use of a variable set to 'a
> reference to' the list variable was shown in the 1997 AppleScript
> Language Guide and was probably known about long before that.
I knew about this, and this is not really my point.
I wasn't aware of the big difference in the loop access
>>> repeat with aChar in theCharsRef
which occurs sometimes(!), depending on the action inside of the loop(!); the AppleScript Language Guide describes the difference in the collation of the result only.
What amazes me is the
>>> repeat with aChar in theChars # Ref # <- Here Ref is actually slower (~2x)!
bit, and the experience that the difference isn't really in the setup of the main loop, but in the use of the conversion
set aChar to aChar as text
that occurred in my original script.
So the difference between
>>> repeat with aChar in theCharsRef # <- without Ref 10 times longer!
>>> set outText to outText & aChar
>>> end repeat
>>> (143.58203125)
and
>>> repeat with aChar in theChars # Ref # <- Here Ref is actually slower (~2x)!
>>> copy aChar to the end of outTextRef # <- without Ref much slower (~15x)
>>> end repeat
>>> (47.761962890625)
shows the interrelationship between the setup of the loop and the actions inside of the loop.
This is what I don't fully understand.
> What Serge noticed sometime around 2000/2001 was that access to list
> items was also greatly speeded up when the list was in a script object.
> He couldn't explain this and asked about it here. (Unfortunately I can't
> find the relevant post in the archives.) It was I who (eventually) made
> the connection with 'a reference to' and also realised that placing 'my'
> or 'its' before a list variable had the same effect.
>
> The speed-up happens when references to items or properties of a list
> have this form:
>
> <element(s) or property> of <list variable> of <script>
>
I'll look into this.
All the best
Thomas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden