Compare speed of reading random(binary file) in VB6 and VB2005
I ever created one project to read a random file(binary, not text) in VB6. It takes only 5 seconds to get all records(structure as below) and store these records in an array, but now i upgraded it to VB2005. I also use the handle-base method(fileget). Very miserable, it takes more then 30 seconds.I do not know why?
!!!!No any error, but i do not know why so slow!!!!
Module1:
Public dataarray(50000) as rec_info
Public datacount as long
Public Structure rec_info
<VBFixedString(8)> Public Data1 as string
Public Data2 as integer
Public Data3 as single
End Structure
Code:
Dim i as long
Dim file_num as integer = FreeFile()
FileOpen(file_num,"xxx.dat",OpenMode.Random, OpenAccess.Read,,14)
i = 0
Do Until EOF(file_num)
i = i + 1
FileGet(file_num,dataarray(i))
Loop
datacount = i
FileClose(file_num)
[1090 byte] By [
Linlin] at [2007-12-28]
Linlin,
I suggest you to look up the FileSystem object because you know that in Visual Basic 2005, there is a new class called My, I don't know you're familiar with this class. The My.Computer.FileSystem object will help you to read the file with the most convenient way.
The following link shows several exanples on the FileSystem object and hope that can help you!
http://msdn2.microsoft.com/en-us/library/0b485hf7.aspx
This not an apt test.
The reason that it is not apt is that VB and DOT.NET have different design centers. VB6 was written when memory was relatively expensive. Dot Net has a different way of doing things. So comparing two different products of two different eras, is literally comparing apples and oranges.
If you want to benchmark disk random access fine against memory random access, I'll be happy to compare the results. Yours won't look very good. Mine will look fantastic.