I have this method where I write 360 lines to disk, and it takes 4040 milliseconds :
[code] system.DebugLog CurrentMethodName
dim previousmilli as int64 = Microseconds/1000
if diko <> nil then
dim f as folderItem = SpecialFolder.Applicationdata.child(App.AppDataFolder)
if not f.Exists then
f.CreateAsFolder
end if
system.debuglog "folderitem: "+ str((Microseconds/1000)-previousmilli)
previousmilli = Microseconds/1000
if f.Exists then
f = f.child("Diko.csv")
dim lines() as string
if Diko.Count > 0 then
For Each key As Variant In Diko.Keys
lines.append(key+chr(9)+";"+tab+Diko.Value(key))
Next
end if
system.debuglog "Dictionary keys: "+ str((Microseconds/1000)-previousmilli)
previousmilli = Microseconds/1000
dim linetowrite as string= join(lines,EndOfLine)
system.debuglog "join lines: "+ str((Microseconds/1000)-previousmilli)
previousmilli = Microseconds/1000
Dim t As TextOutputStream
If f <> Nil Then
t = TextOutputStream.Create(f)
t.Write(linetowrite)
t.Close
End If
end if
system.debuglog "write to disk: "+ str((Microseconds/1000)-previousmilli)
[/code]
its confusing how you are checking F for nil and exists … if it exists then it can’t be nil so the NIL check is useless
Why go thru DIKO (a dictionary) to create a array of lines, then join those into a string
why not just write each line from the dictionary and forgo the array
if Diko.Count > 0 then
For Each key As Variant In Diko.Keys
t.writeline key+chr(9)+";"+tab+Diko.Value(key)
Next
end if
yes, I know that doesn’t explain the delay… but perhaps removing reduncacy might fix the issue
Actually, that was what I was doing before and I thought the delay was due to to writing each line, so I went to write a big chunk. As you can see above, creating the array from the dictionary takes only 9 milliseconds.
[quote=370752:@Antonio Rinaldi]How big are the lines? (or the final file size)
I just tried your code on my mac (HD) and is really quicker in the write phase.
So:
A) your data is greater than my test data (probably)
B) you have some trouble on your SSD[/quote]
The final file size in 25K. Should not be such a problem.
I am going to check my SSD, but let alone on High Sierra startup, I would see immediately see if it had become as slow as a regular hard drive.
This may help to see how much time is the write and how much is creating the file:
previousmilli = Microseconds/1000
Dim t As TextOutputStream
If f <> Nil Then
t = TextOutputStream.Create(f)
system.debuglog "create file: "+ str((Microseconds/1000)-previousmilli)
previousmilli = Microseconds/1000
t.Write(linetowrite)
system.debuglog "write file: "+ str((Microseconds/1000)-previousmilli)
t.Close
End If