Re: really slow repeat loop
Re: really slow repeat loop
- Subject: Re: really slow repeat loop
- From: Paul Skinner <email@hidden>
- Date: Wed, 19 Jan 2005 03:38:26 -0500
On Jan 18, 2005, at 7:17 PM, Gabe Benveniste wrote:
I'm doing this loop in AppleScript Studio but was told this was more
of an applescript issue in general.
This loop is REALLY slow and I'm looking for a way to make it faster.
... snip slow loop
On Jan 18, 2005, at 9:02 PM, Andrew Oliver wrote:
On Tue, 18 Jan 2005 17:37:53 -0800, Andrew Oliver wrote: As has been
covered many times before, when appending to a list it is far, far
faster to:
copy username to end of user_list
Since it involves less memory moving, especially with large lists.
On Jan 18, 2005, at 8:51 PM, Shane Stanley wrote:
Really? This suggests otherwise:
... snip script displaying speed difference
On Jan 18, 2005, at 9:02 PM, Andrew Oliver wrote:
Oops. Did I get that wrong or are there cases where it does work the
other way round? Maybe when dereferencing objects rather than dealing
with primitives? Or maybe I just need more coffee. <sigh>
Andrew
Since Andrew didn't actually state a second list-building method for
his comparison ( common in political speech ) he can't really be wrong.
: )
Perhaps this is more demonstrative of the issue...
set timerList to {}
set x to {}
set timer to current date
repeat with i from 1 to 25000
--1 append a value to a list.
set end of x to i
end repeat
set the end of timerList to (current date) - timer
set x to {}
set timer to current date
repeat with i from 1 to 25000
--2 copy a value and append it to a list.
copy i to end of x
end repeat
set the end of timerList to (current date) - timer
set x to {}
set timer to current date
repeat with i from 1 to 25000
--3 copy the list and append a value. Assign the result to x.
set x to x & i
end repeat
set the end of timerList to (current date) - timer
set x to {}
set timer to current date
repeat with i from 1 to 25000
--4 copy the list, copy a value and append the copied value. Copy the
result to x.
copy x & i to x
end repeat
set the end of timerList to (current date) - timer
-->{1, 141, 303, 510}
Now if you use a reference to the list...
To answer the original question, * set checkboxList to (ask the
application only once for all the checkbox values). Set usernameList
to (Ask it once for all the username values). Loop through the
checkboxList in Applescript; not in the app. If the value is true for
item i of the checkboxList then get item i from the usernameList.
* Assumes from structure that your posted code is in a tell app block.
Inter-application messages are slow. Use them sparingly when possible.
Even if this is all intra-application queries cost time.
Optimally, If the application supports it...
On Jan 18, 2005, at 8:37 PM, Andrew Oliver wrote:
set theRows to every data row in theDataSource whose data cell
"checkbox_row" is true
or even...
set user_list to data cell "username" of every data row in
theDataSource whose data cell "checkbox_row" is true
Paul Skinner
--not sleepy.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden