I am running tests looking at the speed of the compiled code and ran into a bottleneck dealing with file IO.
This routine takes 17.247 seconds the same code in .net takes .657 seconds. I must be doing something wrong writing to the file system for xojo to be that slow.
Dim f as FolderItem
f=new FolderItem(“ArrayText.txt”)
Dim Output as TextOutputStream = TextOutputStream.Create(f)
For x = 1 To 2000000
Output.WriteLine(cstr(x) + " : " + cstr(y(x)))
next
Output.Close
Possibly the .net version caches the write and writes as a chunk.
Try creating one large string and writing it in a single lump at the end of the loop.
You would do that by adding the rows to an array, then using JOIN on the array.
As Christian indicated, writing or reading a single line is MUCH slower than reading or writing in one go - after all your hard disk or SSD is slower by a factor of 10,000 than your memory.
I would not have believed it going from cstr to str dropped another 4 seconds. from 17 to 5 seconds overall. Still not close to the .net time but much better.
The frustrating part is that the process to load and sort the array is MUCH faster in xojo, but when it comes to writing out to disk xojo is much slower. So far I have used an output array, Str() instead of cstr() and #pragma BackgroundTasks False and the time went from 17 seconds to 4 seconds.
This is part of a test to see if it I can save some time using xojo to create files to load into a data warehouse.
Just timing the write to file portion but here is the entire listing of the test
Print"The magic happens here."
Dim sOut as string
Dim x As Int32
Dim y(2000000) as Double
dim lineout(2000000) as string
#Pragma BackgroundTasks False
dim a as Double
'Dim StartTime As DateTime = datetime.Now
dim Interval as new DateInterval
For x = 1 To 2000000
y(x) = x/2000000
Next x
Print “Pass One”
For x = 1 To 2000000
a = y(x)
lineout(x) = str(x) + " : " + str(y(x))
Next x
Print “…”
Print “… Write to File”
'Start time here so we just time the writing to disk
Dim StartTime As DateTime = datetime.Now
Dim f as FolderItem
f=new FolderItem(“ArrayText.txt”)
Dim Output as TextOutputStream = TextOutputStream.Create(f)
For x = 1 To 2000000
Output.Write(lineout(x))
next
output.Flush
Output.Close