Re: applescript-users digest, Vol 3 #2735 - 22 msgs
Re: applescript-users digest, Vol 3 #2735 - 22 msgs
- Subject: Re: applescript-users digest, Vol 3 #2735 - 22 msgs
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 03 Jun 2004 21:15:42 -0700
On 6/3/04 8:51 PM, "Matthew Strange" <email@hidden> wrote:
>
On Jun 3, 2004, at 9:35 PM, Paul Berkowitz wrote:
>
>
>> I want to manipulate a list by taking some items out....
>
>
> You can improve performance by using 'set' rather than copy...
>
>
I normally trust Paul's advice without question, but this assertion
>
caught me off guard. So I did some testing, and at its simplest level,
>
copy and set seem to me to be identical. On my G4/1.2GHz running
>
10.3.4...
>
>
set ListA to {}
>
repeat 10000 times
>
copy "a" to the end of ListA
>
end repeat
>
takes 23 seconds
>
>
set ListB to {}
>
repeat 10000 times
>
set the end of ListB to "a"
>
end repeat
>
takes 23 seconds
>
>
Identical timing, which leads me to ask: "why does Paul say set is more
>
efficient than copy?"
>
Matt Strange
>
email@hidden
Probably things have improved enormously on modern machines. But it's not
just speed: 'copy' makes a new copy in memory. It may not matter so much for
'copy to end of list'. I don't know the low-level machine events involved,
but was always told (on this list) that 'set' was better because it just
points a variable to a new value. Perhaps this doesn't apply dealing with
list items - someone more knowledgeable will have to chime in.
Whatever differences there may possibly be would be increased greatly if you
were adding application objects rather than the single character "a", of
course.
>
>
PS: the 'other' method of concatenating a list takes 48 seconds (twice
>
as long)...
>
set ListC to {}
>
repeat 10000 times
>
set ListC to ListC & "a"
>
end repeat
That version rewrites the list 10000 times, starting from scratch each time.
--
Paul Berkowitz
_______________________________________________
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.