Re: cost of repeats (was Re: why is applescript so slow???)
Re: cost of repeats (was Re: why is applescript so slow???)
- Subject: Re: cost of repeats (was Re: why is applescript so slow???)
- From: Jake Pietrykowski <email@hidden>
- Date: Tue, 30 Nov 2004 20:32:50 -0600
It's just logic really...with example (1) you'd be forcing the script to
count twice. Here...try this...got a stopwatch? j/k ;-)
(* start of script *)
set x to 100000
-- Script 1
set counter to 0
repeat with i from 1 to x
set counter to counter + 1
set counter to counter + 1
end repeat
-- Script 2
set counter to 0
repeat with i from 1 to x
set counter to counter + 1
end repeat
repeat with i from 1 to x
set counter to counter + 1
end repeat
(* end of script *)
While BOTH scripts will indeed generate the SAME results...on my PBG4
400mHz...100000 was a high enough number for me to get a 2.5 second count
for script 1 and a 3 second count for script 2. I'd imagine the faster your
machine, you'd have to keep adding zeros (0) to x so increase the script run
time.
Placing the REAL TIME test aside...its really just LOGIC. If x = 1,000,000,
why count from zero to 1 million twice? Counting alone takes time...remove
any script action and see the LOGIC.
(1)
repeat with i from 1 to 100
end repeat
OR
(2)
repeat with i from 1 to 100
end repeat
repeat with i from 1 to 100
end repeat
While the script does NOTHING in either case, script 2 must count to a total
of 200 before complete vs. script 1, a total count of only 100.
Hope this helps...
Kindest Regards,
Jake
On 11/30/04 8:06 PM, "halloolli" <email@hidden> wrote:
> From: "wayne melrose" <email@hidden>
>
>> After a quick glance at your code, and I mean quick, I would suggest
>> trying to put your repeats into the same loop..
>
> pardon, so, given the two scripts
>
> (1) repeat with i in theList
> do_one_thing
> end repeat
> repeat with i in theList
> do_another_thing
> end repeat
>
> and
>
> (2) repeat with i in theList
> do_one_thing
> do_another_thing
> end repeat
>
>
>
> does your statement mean that script (1) is substantially slower then (2)?
> well, i might do some tests, but in the meanwhile i want to ask: why does a
> loop itself shall cost so much?
>
> thanks, olli
>
>
> _______________________________________________
> 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
_______________________________________________
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