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: Fri, 26 Apr 2002 02:13:34 +0100
"charles" wrote on Thu, 25 Apr 2002 22:21:45 +0100:
>
I hadn't heard about "mylist" as a variant on "a reference to" for dealing
>
with lists.
>
>
However my tests (OSX) suggest it's a lot slower:
>
>
set thelist to {}
>
set isalist to my thelist
>
set list2 to {}
>
set list3 to a reference to list2
>
>
set starttime to current date
>
repeat 2000 times
>
set end of isalist to "2"
>
end repeat
>
set endtime to current date
>
>
set twostart to current date
>
repeat 2000 times
>
set end of list3 to "2"
>
end repeat
>
set twoend to current date
>
{(endtime - starttime), (twoend - twostart)}
>
>
I find that mylist is slower, by a factor of 2.
This is because you're not using 'my' in your repeat loop. The point is
that you should use the reference *expression* 'my thelist', which is
another way of saying 'thelist of <<script>>'. If you look at the result
of setting list3 to 'a reference to list2', you'll see that it's 'list2
of <<script>>'. The two expressions are therefore very similar. The
difference is that one is held in a variable ('list3') and the other is
written directly into the script.
set thelist to {}
set list2 to {}
set list3 to a reference to list2
set starttime to current date
repeat 10000 times
set end of my thelist to "2" -- 'my thelist' = 'thelist of <<script>>'
end repeat
set endtime to current date
set twostart to current date
repeat 10000 times
set end of list3 to "2" -- list3's value is 'list2 of <<script>>'
end repeat
set twoend to current date
{(endtime - starttime), (twoend - twostart)}
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.
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.