Re: Speed of applets vs. compiled scripts
Re: Speed of applets vs. compiled scripts
- Subject: Re: Speed of applets vs. compiled scripts
- From: "Geoff Canyon" <email@hidden>
- Date: Mon, 28 Jan 2002 10:09:16 -0800
At 12:09 PM -0500 1/28/02, email@hidden wrote:
>
You only have to try divisors up to sqrt(i), rather than i/2. As i gets large,
>
the savings are significant. (Specifically, you get an advantage of sqrt(i)/2.)
The advantage of only calculating to the square root is huge. The changes below are more modest, cutting the time roughly in half.
set t to (current date)
set pList to {2}
repeat with i from 3 to 10001 by 2
set tHowMany to count pList
set tStopVal to sqrt (i)
repeat with j from 1 to tHowMany
set tWhichPrime to item j of pList
if tWhichPrime > tStopVal then
set end of pList to i
exit repeat
end if
if i mod tWhichPrime = 0 then exit repeat
end repeat
end repeat