Hi!
I'm just wondering about the speed in reading a binary file.
I read a binary file with the following code (br is a binaryfile object):
The code reads a proprietary fileformat with geo coordinates (and some other data) in it. I have removed the stuff that stores the data in a database but the resulting part is quite slow too. The source looks quite minimal to me but I think it is very slow to read the data. For example reading a 800kb file with nearly 11000 koordinate pairs took one minute (with storing part of the koordinates in a database, the file reading part takes 25 seconds). If I convert the data to a GPX file the resulting GPX file is nearly 1.9MB in size. But loading it with the XMLReader and storing the same amount of koordinates in a database only takes 42 seconds. Since the XML library has to do much more checking etc. I have thought the direct load of the binary file would be much faster than reading a much larger and more complex GPX file.
Is this because the binaryfile has to be opened in random access mode? Is there a possibility to speed up the sequential reading of a binary file? Is there a complete other way to read the file?
Hints are very welcome.
Markus
I'm just wondering about the speed in reading a binary file.
I read a binary file with the following code (br is a binaryfile object):
B4X:
FileOpen(c1, pFileName, cRandom)
br.New1(c1, True)
br.Position = 0
br.ReadString ' Skip header
fileVersion = br.ReadInt32 ' Read fileversion
br.Offset(32) ' Skip not needed data
Do While br.Position < br.Length
br.ReadInt32 'entryType
latitude = br.ReadDouble 'latitude
longitude = br.ReadDouble 'longitude
' Skip rest of data block
If fileVersion >= 230 Then
br.Offset(72)
Else If fileVersion >= 229
br.Offset(56)
Else
br.Offset(40)
End If
Loop
The code reads a proprietary fileformat with geo coordinates (and some other data) in it. I have removed the stuff that stores the data in a database but the resulting part is quite slow too. The source looks quite minimal to me but I think it is very slow to read the data. For example reading a 800kb file with nearly 11000 koordinate pairs took one minute (with storing part of the koordinates in a database, the file reading part takes 25 seconds). If I convert the data to a GPX file the resulting GPX file is nearly 1.9MB in size. But loading it with the XMLReader and storing the same amount of koordinates in a database only takes 42 seconds. Since the XML library has to do much more checking etc. I have thought the direct load of the binary file would be much faster than reading a much larger and more complex GPX file.
Is this because the binaryfile has to be opened in random access mode? Is there a possibility to speed up the sequential reading of a binary file? Is there a complete other way to read the file?
Hints are very welcome.
Markus