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: email@hidden (Michael Sullivan)
- Date: Thu, 25 Apr 2002 22:41:08 -0400
- Organization: Society for the Incurably Pompous
Nigel Garvey writes:
>
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 disagree here with the characterization of this as only worthwhile
with very large lists.
It starts to make big differences in some very standard algorithms
around a few hundred items, since it's an O(n) v O(1) difference.
Any function that traverses a list which might get to more than 500 or
so items long will benefit noticeably from this optimization.
I don't think of that as very large, although it's true that most of the
time we need a list in applescript, there is no need for it to hold that
many items.
But I often see people ignore potential solutions that involve
traversing 1000+ item lists because of the speed issue, when using this
tweak suddenly makes traversing lists up to 20,000 or so possible in
real time on modern macs. Even on this old sluggish stock 7300, I can
traverse a 10K item list in 38 ticks -- that's a barely noticeable wait
within a normal function.
When I write handlers that take or generate lists, I now tend to use
this optimization automatically, even if I don't think it's all that
likely to be necessary. Once you get used to it, it's very simple to
do.
Michael
_______________________________________________
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.