How to make faster? Takes too long!

ghs215
01-11-2005, 07:54 AM
Here is my code. There has to be a way to make it faster. The read takes about 12 minutes (CDataList) and the rest (form1) takes 2-5 hours.

The text file contains binary. 512 bits space delimited. The file also has 70,000 lines of this. (Below is only one line.)

0010000100100000 0000100000000000 1101101011011111 1001111000100100 0000000000000000 0000000000000000 1111111111111111 1100010110001000 0111111101111111 0000000100000000 1111111111111111 0111110110111011 0000000000000000 0000000001000000 0000011000000000 0000010000000101 0001000010010000 0001000000000000 0000010000100000 0000000000000000 0010010111000001 0101001001001001 1011111100001111 1011001110101100 0000011001101000 0000000000000000 0000000000000000 0010000100000000 0011000000010000 0000000000000000 0000001000000001 0000000000100000

ghs215
01-11-2005, 07:56 AM
form1. This is the slow one.

Public Class Form1
Private Sub cmdGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGet.Click
open.ShowDialog() 'open windows common dialog box
Dim myDataWordsFromFile As New CDataList()
myDataWordsFromFile.LoadDataWordObjects(open.FileName) 'Pass FileName to Class CDataList
Try
Dim i As Integer
For i = 0 To myDataWordsFromFile.TotalMessageCount - 1 'Get TotalMessageCount from Class CDataList
lvwDataWordObjects.Items.Add(myDataWordsFromFile.getDataWords(i + 1).dw1) 'ivwObjects is the ListView, Add record row
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw2) 'SubItems is column
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw3)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw4)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw5)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw6)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw7)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw8)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw9)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw10)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw11)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw12)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw13)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw14)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw15)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw16)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw17)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw18)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw19)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw20)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw21)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw22)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw23)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw24)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw25)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw26)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw27)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw28)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw29)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw30)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw31)
lvwDataWordObjects.Items(i).SubItems.Add(myDataWordsFromFile.getDataWo rds(i + 1).dw32) 'End of SubItems (Last Column)
Next
Catch exc As Exception
MessageBox.Show(exc.Message, "Terminated")
Exit Sub
End Try
End Sub
End Class

ghs215
01-11-2005, 07:58 AM
CDataList - takes approx 12 min

Public Class CDataList

Private _DataWordObjects As New Collection 'collection holds instances of dwXX (32 Data Words) objects

Public Sub New()
End Sub
Public Sub LoadDataWordObjects(ByVal Filename As String) 'Recieve FileName
Dim ReadFile As New System.IO.StreamReader(Filename) 'Initialises the stream reader and opens the file
Dim WholeString As String, SplitString As String() 'Holds the data read from the file
Dim DataWords As CDataWords 'Instance
'read the data from file
Try
Do Until ReadFile.Peek = -1 'Loops until the end of the file is reached
WholeString = ReadFile.ReadLine 'Read the file
DataWords = New CDataWords() 'Make Instance(s)
SplitString = WholeString.Split(" ") 'Split the WholeString and Store into SplitString
DataWords.dw1 = SplitString(0)
DataWords.dw2 = SplitString(1) 'Put in array
DataWords.dw3 = SplitString(2) 'each is a 16bit chunk
DataWords.dw4 = SplitString(3) 'There should be 32 chunks
DataWords.dw5 = SplitString(4)
DataWords.dw6 = SplitString(5)
DataWords.dw7 = SplitString(6)
DataWords.dw8 = SplitString(7)
DataWords.dw9 = SplitString(8)
DataWords.dw10 = SplitString(9)
DataWords.dw11 = SplitString(10)
DataWords.dw12 = SplitString(11)
DataWords.dw13 = SplitString(12)
DataWords.dw14 = SplitString(13)
DataWords.dw15 = SplitString(14)
DataWords.dw16 = SplitString(15)
DataWords.dw17 = SplitString(16)
DataWords.dw18 = SplitString(17)
DataWords.dw19 = SplitString(18)
DataWords.dw20 = SplitString(19)
DataWords.dw21 = SplitString(20)
DataWords.dw22 = SplitString(21)
DataWords.dw23 = SplitString(22)
DataWords.dw24 = SplitString(23)
DataWords.dw25 = SplitString(24)
DataWords.dw26 = SplitString(25)
DataWords.dw27 = SplitString(26)
DataWords.dw28 = SplitString(27)
DataWords.dw29 = SplitString(28)
DataWords.dw30 = SplitString(29)
DataWords.dw31 = SplitString(30)
DataWords.dw32 = SplitString(31) 'end of SplitString
_DataWordObjects.Add(DataWords) 'stores instances of dwXX (DataWords) and collects them into this array
Loop
Catch exc As Exception
MessageBox.Show(exc.Message, "Error. Terminated")
Exit Sub
End Try
End Sub


Public Function TotalMessageCount() As Integer
Return _DataWordObjects.Count
End Function
Public Function getDataWords(ByVal index As Integer) As CDataWords
Return _DataWordObjects.Item(index)
End Function
End Class

ghs215
01-11-2005, 07:59 AM
CDataWords

Public Class CDataWords
Private _mdw1 As String, _mdw2 As String, _mdw3 As String, _mdw4 As String, _
_mdw5 As String, _mdw6 As String, _mdw7 As String, _mdw8 As String, _mdw9 As String, _
_mdw10 As String, _mdw11 As String, _mdw12 As String, _mdw13 As String, _mdw14 As String, _
_mdw15 As String, _mdw16 As String, _mdw17 As String, _mdw18 As String, _mdw19 As String, _
_mdw20 As String, _mdw21 As String, _mdw22 As String, _mdw23 As String, _mdw24 As String, _
_mdw25 As String, _mdw26 As String, _mdw27 As String, _mdw28 As String, _mdw29 As String, _
_mdw30 As String, _mdw31 As String, _mdw32 As String

Public Property dw1() As String
Get
Return _mdw1
End Get
Set(ByVal Value As String)
_mdw1 = Value
End Set
End Property

Public Property dw2() As String
Get
Return _mdw2
End Get
Set(ByVal Value As String)
_mdw2 = Value
End Set
End Property

Public Property dw3() As String
Get
Return _mdw3
End Get
Set(ByVal Value As String)
_mdw3 = Value
End Set
End Property

Public Property dw4() As String
Get
Return _mdw4
End Get
Set(ByVal Value As String)
_mdw4 = Value
End Set
End Property

Public Property dw5() As String
Get
Return _mdw5
End Get
Set(ByVal Value As String)
_mdw5 = Value
End Set
End Property

Public Property dw6() As String
Get
Return _mdw6
End Get
Set(ByVal Value As String)
_mdw6 = Value
End Set
End Property

Public Property dw7() As String
Get
Return _mdw7
End Get
Set(ByVal Value As String)
_mdw7 = Value
End Set
End Property

Public Property dw8() As String
Get
Return _mdw8
End Get
Set(ByVal Value As String)
_mdw8 = Value
End Set
End Property

Public Property dw9() As String
Get
Return _mdw9
End Get
Set(ByVal Value As String)
_mdw9 = Value
End Set
End Property

Public Property dw10() As String
Get
Return _mdw10
End Get
Set(ByVal Value As String)
_mdw10 = Value
End Set
End Property

Public Property dw11() As String
Get
Return _mdw11
End Get
Set(ByVal Value As String)
_mdw11 = Value
End Set
End Property

Public Property dw12() As String
Get
Return _mdw12
End Get
Set(ByVal Value As String)
_mdw12 = Value
End Set
End Property

Public Property dw13() As String
Get
Return _mdw13
End Get
Set(ByVal Value As String)
_mdw13 = Value
End Set
End Property

Public Property dw14() As String
Get
Return _mdw14
End Get
Set(ByVal Value As String)
_mdw14 = Value
End Set
End Property

Public Property dw15() As String
Get
Return _mdw15
End Get
Set(ByVal Value As String)
_mdw15 = Value
End Set
End Property

Public Property dw16() As String
Get
Return _mdw16
End Get
Set(ByVal Value As String)
_mdw16 = Value
End Set
End Property

Public Property dw17() As String
Get
Return _mdw17
End Get
Set(ByVal Value As String)
_mdw17 = Value
End Set
End Property

Public Property dw18() As String
Get
Return _mdw18
End Get
Set(ByVal Value As String)
_mdw18 = Value
End Set
End Property

Public Property dw19() As String
Get
Return _mdw19
End Get
Set(ByVal Value As String)
_mdw19 = Value
End Set
End Property

Public Property dw20() As String
Get
Return _mdw20
End Get
Set(ByVal Value As String)
_mdw20 = Value
End Set
End Property

Public Property dw21() As String
Get
Return _mdw21
End Get
Set(ByVal Value As String)
_mdw21 = Value
End Set
End Property

Public Property dw22() As String
Get
Return _mdw22
End Get
Set(ByVal Value As String)
_mdw22 = Value
End Set
End Property

Public Property dw23() As String
Get
Return _mdw23
End Get
Set(ByVal Value As String)
_mdw23 = Value
End Set
End Property

Public Property dw24() As String
Get
Return _mdw24
End Get
Set(ByVal Value As String)
_mdw24 = Value
End Set
End Property

Public Property dw25() As String
Get
Return _mdw25
End Get
Set(ByVal Value As String)
_mdw25 = Value
End Set
End Property

Public Property dw26() As String
Get
Return _mdw26
End Get
Set(ByVal Value As String)
_mdw26 = Value
End Set
End Property

Public Property dw27() As String
Get
Return _mdw27
End Get
Set(ByVal Value As String)
_mdw27 = Value
End Set
End Property

Public Property dw28() As String
Get
Return _mdw28
End Get
Set(ByVal Value As String)
_mdw28 = Value
End Set
End Property

Public Property dw29() As String
Get
Return _mdw29
End Get
Set(ByVal Value As String)
_mdw29 = Value
End Set
End Property

Public Property dw30() As String
Get
Return _mdw30
End Get
Set(ByVal Value As String)
_mdw30 = Value
End Set
End Property

Public Property dw31() As String
Get
Return _mdw31
End Get
Set(ByVal Value As String)
_mdw31 = Value
End Set
End Property

Public Property dw32() As String
Get
Return _mdw32
End Get
Set(ByVal Value As String)
_mdw32 = Value
End Set
End Property

'End
End Class


Any Ideas would be great!

excaliber
01-11-2005, 02:26 PM
If I understand your code correctly, lvwDataWordObjects is a ListView object. My guess is this is the source of your problem. The rest of your code is fairly straight forward (the file access is efficient, and you are just saving it to string variables).

On the other hand, each time you add/edit/manipulate the items/subitems in a ListView, it forces a refresh of the entire object, which can get agonizingly slow with lots of data. Here is the solution. Before entering the For Loop, call this method:


lvwDataWordObjects.BeginUpdate


And after you are done with the entire loop, call this method:


lvwDataWordObjects.EndUpdate


These methods force the Listview to not update the control (the visible, painted object itself) until the EndUpdate method is called. Theoretically, this should speed it up a lot. Let me know if this helps. If not, more thinking is needed :)

piggybank1974
01-11-2005, 03:08 PM
instead of using 32 private strings why don't you use only one, and make it and array instead, you could even make it a ArrayList here something like this:

--Note-- The TempString must be a member of DataWords

Dim tempString(31) as string ' 0 to 31

SplitString = WholeString.Split(" ") 'Split the WholeString and Store into SplitString

For A as int32 =0 to 31
DataWords.TempString(A) = SplitString(A)
Next A


I cannot believe that anybody has not mentioned this as it's good programming practice to make your code as small as possible, but to make it readable.

the pig..

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum