Speed of applets vs. compiled scripts
Speed of applets vs. compiled scripts
- Subject: Speed of applets vs. compiled scripts
- From: "Marc K. Myers" <email@hidden>
- Date: Mon, 28 Jan 2002 11:18:36 -0500
- Organization: [very little]
I wrote a little script to generate a list of all the prime numbers from
2 to 10001. I ran it under Script Editor and it took 586 seconds. Just
out of curiosity I ran the same script as an applet. It ran for 998
seconds! Can anyone tell me why there is such a difference? I had
expected the applet to run faster since it didn't have the overhead of
the Script Editor application. Also, is there a faster algorithm for
generating a list of primes?
Here's the script:
set t to (current date)
set pList to {2}
repeat with i from 3 to 10001 by 2
repeat with j from 1 to count pList
if item j of pList > (i / 2) then
set end of pList to i
exit repeat
end if
if i mod (item j of pList) = 0 then exit repeat
end repeat
end repeat
set AppleScript's text item delimiters to {return}
set pText to pList as text
set pText to (pText & return & return & "Execution time: " & [optn-L]
((current date) - t) as text) & " seconds"
set fileID to open for access file "Prime Numbers" with write permission
try
set eof fileID to 0
write pText to fileID starting at eof
close access fileID
on error m number n
try
set AppleScript's text item delimiters to ""
close access fileID
end try
display dialog "Error Encountered: " & (n as text) & return & m
end try
set AppleScript's text item delimiters to ""
NB: "[optn-L]" replaces the AppleScript continuation character
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[1/28/02 11:12:29 AM]