Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: list-building performance




Le 2 juin 07 à 02:57:46, Nigel Redmon a écrit :

I expected that appending items to a list by setting (or copying to) the end of a list would be fairly efficient, but found it's not. It appears that the process grows with the size of a list, so that the time involved grows exponentially, at least with the ways I've tried so far. For instance, creating a list as follows take about 1 second for 500 loop iterations, 4 seconds for 1000, and 32 seconds for 2000:

set startTime to (time of (current date))
set theList1 to {}
set timeStamp to 0
repeat with idx from 1 to 2000
	set end of theList1 to {timeStamp, noteOn, 60, 100}
	set end of theList1 to {timeStamp + 1, noteOn, 60, 0}
	set timeStamp to timeStamp + 1
end repeat
(time of (current date)) - startTime



this small changes fasten it drastically:

property theList1 : {}
set noteOn to false

set startTime to (time of (current date))
set theList1 to {}
set timeStamp to 0
repeat with idx from 1 to 2000
	set end of my theList1 to {timeStamp, noteOn, 60, 100}
	set end of my theList1 to {timeStamp + 1, noteOn, 60, 0}
	set timeStamp to timeStamp + 1
end repeat
(time of (current date)) - startTime

noteon was not defined in your original script.

Yvan KOENIG _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >list-building performance (From: Nigel Redmon <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.