Hi peavine.
My initial timings were admittedly crudely done, mainly to establish which method was the faster. The scripts were run in separate Script Debugger windows and were timed with SD’s built-in timer. Both timings included the time taken to build the 4,000-item list — which isn’t a good way to compare the performances of the methods themselves — and I didn’t bother pausing the BOINC tasks I normally have running in the background.
If I substitute the ‘do shell script’ command for the ASObjC stuff in my post #16 timing script, comment out the second repeat to leave the number of items at 4,000, and have the handler return the final message instead of displaying it:
use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use scripting additions
on main()
set Test_List to {"217.0 241.0 217224033 37.404", "225.0 241.0 057181074 25.407", "249.0 241.0 193039045 11.751", "241.0 241.0 247147030 35.026"}
set sample to Test_List
repeat 999 times
set Test_List to Test_List & sample
end repeat
(*set sample to Test_List
repeat 99 times
set Test_List to Test_List & sample
end repeat*)
set sample to missing value
count Test_List
say result
set start to current application's class "NSDate"'s new() -- Start timing here.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set Test_String to Test_List as text
set AppleScript's text item delimiters to astid
do shell script "echo " & Test_String's quoted form & "| cut -d '" & space & "' -f3 "
return "That took " & -(start's timeIntervalSinceNow()) & " seconds."
end main
main()
… the result is typically “That took 0.049322962761 seconds.”, ± 0.003 seconds, in Script Editor with BOINC paused on my machine. The same arrangement with the original ASObjC/regex code gives “That took 0.010099053383 seconds.”, ± 0.001 seconds.
With the second repeat uncommented to raise the number of items to 400,000, the ASObjC version typically returns “That took 1.024765014648 seconds.”, ± 0.008 seconds. The shell script version errors out with “The command exited with a non-zero status.”
Intriguingly, if the shell script version’s modified to be able to handle 40,000 items — ie. the text is written out to a file which the shell script then reads — the shell script’s faster than the ASObjC with that many items:
use AppleScript version "2.4" -- OS X 10.10 (Yosemite) or later
use framework "Foundation"
use scripting additions
on main()
set Test_List to {"217.0 241.0 217224033 37.404", "225.0 241.0 057181074 25.407", "249.0 241.0 193039045 11.751", "241.0 241.0 247147030 35.026"}
set sample to Test_List
repeat 999 times
set Test_List to Test_List & sample
end repeat
set sample to Test_List
repeat 99 times
set Test_List to Test_List & sample
end repeat
set sample to missing value
count Test_List
say result
set start to current application's class "NSDate"'s new() -- Start timing here.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to linefeed
set Test_String to Test_List as text
set AppleScript's text item delimiters to astid
set Text_File to ((path to desktop as text) & "Test.txt") as «class furl»
set fRef to (open for access Text_File with write permission)
try
set eof fRef to 0
write Test_String as «class utf8» to fRef
close access fRef
on error errMsg
close access fRef
display dialog errMsg buttons {"Stop"} default button 1 cancel button 1
end try
do shell script "cut -d '" & space & "' -f3 <" & quoted form of POSIX path of Text_File
return "That took " & -(start's timeIntervalSinceNow()) & " seconds."
end main
main()
--> "That took 0.783697009087 seconds."