Re: "mylist" vs "a reference to" - speed difference
Re: "mylist" vs "a reference to" - speed difference
- Subject: Re: "mylist" vs "a reference to" - speed difference
- From: Nigel Garvey <email@hidden>
- Date: Sat, 27 Apr 2002 03:00:59 +0100
Arthur J Knapp wrote on Fri, 26 Apr 2002 09:41:04 -0400:
>
> Subject: Re: "mylist" vs "a reference to" - speed difference
>
> Date: Fri, 26 Apr 2002 02:13:34 +0100
>
> From: Nigel Garvey <email@hidden>
>
>
> Your line 'set isalist to my thelist' just sets 'isalist' to the same as
>
> 'thelist'. The speed gain comes from accessing items in the list while
>
> refering to the list with an expression rather than a simple variable
>
> name. It's only worthwhile with very large lists and/or with a very large
>
> number of operations on the items.
>
>
I just wanted to point out that Nigel here was the guy who discovered
>
that the "my" technique was actually faster than the "Serge" technique of
>
directly calling a script object's properties and methods, (found by Serge
>
Belleudy-d'Espinose, of course).
Thanks to Arthur for the PR. :-) But what I actually discovered was that
placing 'my' in front of a list variable caused a speed increase similar
to that of the Serge technique. I then discovered that it only worked
with globals and properties (whereas Serge's script-object approach could
be used either globally or locally) and later deduced that both methods
owed their speed to the fact that they caused list variables to be
referenced rather than being accessed directly.
item i of bigList -- direct access
item i of scriptObject's bigList -- access via reference (Serge's
method)
item i of my bigList -- access via reference ('my')
The 'me' in this case is the script itself, so 'my bigList' is equivalent
to 'bigList of <<script>> - which also happens to be the result of
getting 'a reference to bigList'. You can prove the equivalence like this:
set bigList to {"big"}
set bigListRef to a reference to bigList
--> bigList of <<script>>
{bigList} = {bigListRef}
--> false (left list contains list variable; right contains reference
variable)
return {my bigList} = {bigList}
--> false (left list contains reference; right contains list variable)
{my bigList} = {bigListRef}
--> true (the lists are equal, so the references are the same)
ASLG mentions that accessing large lists via references is far faster
than using the list variables directly (but doesn't explain why). My
theory is that the reason 'my' and the Serge techinque are even faster
than using reference variables is because they're compiled directly into
the script, whereas reference variables have to be fetched and evaluated.
NG
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.