While the URL syntax is much easier to read, for append operations my understanding is that the convenience it offers the scripter comes at a significant cost to performance. IIRC it treats the file contents as a complete chunk, so "put after" will first read the entire file, append the data in memory, then write the whole thing out again. In contrast, when a file is first opened in append mode it will only write to the end of the file, so none of the data written previously is ever touched by subsequent writes.
I tested this hypothesis with the following code. Try a few runs with different values in the variable n defined on the first line. At 10 iterations "put URL" is still slower than "open for append" but not bad. However, as you increase the number of iterations to 1000 or 10000 the time for AppendData1 grows exponentially, whereas time for AppendData2 grows linearly:
Code: Select all
on mouseUp
put 1000 into n
put "This is a test" into s
put specialFolderPath("desktop")&"/TestDumpFile1.txt" into tFile1
put specialFolderPath("desktop")&"/TestDumpFile2.txt" into tFile2
--
-- "put URL"
put the millisecs into t
repeat n
AppendData1 s, tFile1
end repeat
put the millisecs - t into t1
--
-- "open for append"
put the millisecs into t
open file tFile2 for append
repeat n
AppendData2 s, tFile2
end repeat
close file tFile2
put the millisecs - t into t2
--
put url ("file:"& tFile1) into tData1
put url ("file:"& tFile2) into tData2
put "URL: "& t1 &" ms"&cr& "Append: "& t2 &" ms"&cr \
&"Files the same? "& (tData1 = tData2)
end mouseUp
on AppendData1 s, tFile
put s&cr after url ("file:"& tFile)
end AppendData1
on AppendData2 s, tFile
write s &cr to file tFile
end AppendData2
For tasks done infrequently it probably doesn't matter much which form you use, but for extremely frequent tasks like file I/O on every keystroke the speed will eventually make a noticeable difference as the size of the data in the file grows.