Re: Speed of applets vs. compiled scripts
Re: Speed of applets vs. compiled scripts
- Subject: Re: Speed of applets vs. compiled scripts
- From: "Marc K. Myers" <email@hidden>
- Date: Mon, 28 Jan 2002 16:47:21 -0500
- Organization: [very little]
My thanks to those who offered me such good advice. By employing the
square root limit, using a reference to the list, and examining only odd
numbers I cut the execution time down to 10 seconds. That's 1.6% of my
original run time! I did notice that getting a square root using the
"sqrt" function was slower than using "i^(1/2)". Using the function
added 10% to my run time. My script now looks like this:
set t to (current date)
set pList to {2}
set pRef to a reference to pList
repeat with i from 3 to 10001 by 2
set vLimit to i ^ (1 / 2)
repeat with j from 1 to count pRef
if item j of pRef > vLimit then
set end of pRef to i
exit repeat
end if
if i mod (item j of pRef) = 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 ""
Now that it runs so quickly I'm going to play around with getting beyond
the limit of list length by writing parts of the list off to a file in
blocks of 4000 primes and reading the blocks back into lists as needed.
I'd prefer not to have to coerce the lists of integers into delimited
blocks of text and (the hard part) back again. Is there a way to write
multiple lists to a file and then read them back one at a time? If not
I'll just write one list to a file and have multiple files.
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[1/28/02 4:27:46 PM]