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:06 -0400
- Organization: Society for the Incurably Pompous
>
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.
It's not though. It's just that you aren't doing it right. :)
"my variable" seems to create a temporary reference, but if you assign
it to a variable, it will be resolved. So you can't use it to place a
reference in another variable.
In fact we can even test this:
set aList to {1, 2, 3}
set aList2 to a reference to aList
set aList3 to my aList
{aList, (aList2), aList3}
--> {{1, 2, 3}, aList of +script;, {1, 2, 3}}
This is different, no?
I ran your script using ticks and got this result:
--> {219, 11}
But if I run this script:
set theList to {}
set isalist to my theList
set list2 to {}
set list3 to a reference to list2
set starttime to the ticks
repeat 2000 times
set end of my isalist to "2"
-- note use of "my isalist" *here*.
end repeat
set endtime to the ticks
set twostart to the ticks
repeat 2000 times
set end of list3 to "2"
end repeat
set twoend to the ticks
{(endtime - starttime), (twoend - twostart)}
--> {10,11}
Much faster.
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.