Why is this so slow?

  • Thread starter Thread starter Jameson King
  • Start date Start date
J

Jameson King

I have a code that reads all the bytes (all of them into an array) of
a file that is 457 kb and converts those byte values into hex and
writes that data to the HDD as text. When I run the program its
literally doing like 3-4 rounds a second (3-4 bytes a second). What
is going on? I remember VB6 being faster than this.
 
Hello Jameson,
I have a code that reads all the bytes (all of them into an array) of
a file that is 457 kb and converts those byte values into hex and
writes that data to the HDD as text. When I run the program its
literally doing like 3-4 rounds a second (3-4 bytes a second). What
is going on? I remember VB6 being faster than this.

Why do you read them into an array first?
Why not read and convert them in one go and then write it directly to
disk like this? (Please check for line breaks.)

Best regards,

Martin

Private Sub FileToHexFile(ByVal InputFile As String, ByVal Outputfile As
String)
Dim sr As System.IO.StreamReader
Dim sw As System.IO.StreamWriter
Dim i As Integer
Dim h As String
Try
If Dir(InputFile).Length > 0 Then
sr = New System.IO.StreamReader(InputFile)
Try
sw = New System.IO.StreamWriter(Outputfile)
While Not sr.Peek = -1
i = sr.Read()
h = "0" & Hex(i)
sw.Write(Strings.Right(h, 2))
End While
sr.Close()
sw.Close()
Catch ex As Exception
MsgBox("Unable to open output file.", MsgBoxStyle.Exclamation)
End Try
End If
Catch ex As Exception
MsgBox("Unable to open input file.", MsgBoxStyle.Exclamation)
End Try
End Sub
 
Jameson King said:
I have a code that reads all the bytes (all of them into an array) of
a file that is 457 kb and converts those byte values into hex and
writes that data to the HDD as text. When I run the program its
literally doing like 3-4 rounds a second (3-4 bytes a second). What
is going on? I remember VB6 being faster than this.


Post your code.
 
Back
Top