[RESOLVED]Why is this so slow?
I have removed all the 'console.writeline' commands from the for..next loop.
The program loads a text file of any size which in this case contains about 5000 lines. It itterates through them looking for specific information.
This can take two or three minutes at the absolute minimum. Is there a reason for this? Or is it just very much slower when in debug mode?
Or, as I am new to VB, have I missed something fairly fundemental?
Code:
If RB2_time.Checked = False Then
' parsing an npc - all damage against this npc
If ComboB2_all_combatants.SelectedItem.ToString.Contains(" ") = True Then
Console.WriteLine(RTB_Selected_File.Lines.GetUpperBound(0))
length_text_file = RTB_Selected_File.Lines.GetUpperBound(0)
For count1 = 0 To length_text_file
current_line = RTB_Selected_File.Lines(count1)
If (current_line.Contains(ComboB2_all_combatants.SelectedItem.ToString) = True) And (RTB_Selected_File.Lines(count1).Contains(non_melee) = True Or RTB_Selected_File.Lines(count1).Contains(melee_hit)) Then
'Console.WriteLine("test " + count1.ToString + " " + RTB_Selected_File.Lines(count1).ToString)
If current_line.EndsWith(".") = True Or current_line.EndsWith("!") = True Then
current_line = current_line.Remove(current_line.Length - 1, 1)
End If
current_line = current_line.Remove(0, 27)
' ******************************
For count2 = 0 To ComboB2_all_combatants.Items.Count - 1
' The code checks that the line of text has both combatants. This is done by ensuring that they are not the same name.
If current_line.StartsWith(display_name_Array(count2)) And display_name_Array(count2).ToString <> ComboB2_all_combatants.SelectedItem.ToString Then
total_damage = 0
count3 = current_line.LastIndexOf("for")
total_damage = Val(total_damage_Array(count2)) + Val(Mid(current_line, count3 + 4, 6))
total_damage_Array(count2) = total_damage
' The code around here checks previous line to see if it was a critical attack
' previous_line critical_hit critical_blast critical_undead
ElseIf current_line.StartsWith(ComboB2_all_combatants.SelectedItem.ToString) And current_line.Contains(display_name_Array(count2)) = True And display_name_Array(count2).ToString <> ComboB2_all_combatants.SelectedItem.ToString Then
total_damage = 0
End If
Next
' ******************************
'count2 = 0
'Do While attack_melee_casterArray(count2) <> ""
' If current_line.Contains(attack_melee_casterArray(count2)) = True Then
' ' updates specific attack type
' End If
' count2 += 1
'Loop
Else
End If
Next
' ===================================================================
' adds the data to the display grid, names, damage, duration, dps etc
Data_ParseTable.Rows.Clear()
For count1 = 0 To total_damage_Array.GetUpperBound(0)
If display_name_Array(count1) <> "" Then
Data_ParseTable.Rows.Add(display_name_Array(count1), Val(total_damage_Array(count1)))
End If
Next
Else ' parse a Player's toon- this is known because there is at least one space in the name.
Console.WriteLine("Parsing a player's toon")
End If
Else ' parse from time to time
End If
[RESOLVED] Re: Why is this so slow?
Quote:
Originally Posted by Lord Orwell
Trust me on this: None of that is the problem. The problem is you have all the data you are messing with in controls. Store the data in an array and manipulate it instead. Transferring data to and from a textbox or a combobox is extremely time consuming. That whole loop with arrays would take abou 1/2 sec.
Thank you everyone who posted, all have helped with my code.
But yes, changing the 'item' access over to arrays made a massive difference.
I have posted the code I have now.
It's funny. I was lyeing in bed this morning thinking that when the file is loaded the program searches through looking for specific information. That takes less than a second, so why should this particular itteration take so long?
Now I know, thx again.:bigyello:
Code:
If Not RB2_time.Checked Then
' parsing an npc - all damage against this npc
If ComboB2_all_combatants.SelectedItem.ToString.Contains(" ") Then
number_combo_index = ComboB2_all_combatants.SelectedIndex
'Console.WriteLine(RTB_Selected_File.Lines.GetUpperBound(0))
length_text_file = RTB_Selected_File.Lines.GetUpperBound(0)
Console.WriteLine("start")
For count1 = 0 To length_text_file
current_line = loaded_file_text_box_Array(count1)
If (current_line.Contains(names_combo_box_Array(number_combo_index).ToString)) And (loaded_file_text_box_Array(count1).Contains(non_melee) Or loaded_file_text_box_Array(count1).Contains(melee_hit)) Then
'Console.WriteLine("test " + count1.ToString + " " + RTB_Selected_File.Lines(count1).ToString)
If current_line.EndsWith(".") = True Or current_line.EndsWith("!") Then
current_line = current_line.Remove(current_line.Length - 1, 1)
End If
current_line = current_line.Remove(0, 27)
' ******************************
For count2 = 0 To names_combo_box_Array.Length - 1
' The code checks that the line of text has both combatants. This is done by ensuring that they are not the same name.
If current_line.StartsWith(display_name_Array(count2)) And display_name_Array(count2).ToString <> names_combo_box_Array(number_combo_index).ToString Then
total_damage = 0
count3 = current_line.LastIndexOf("for")
count4 = current_line.LastIndexOf("points")
total_damage = Convert.ToInt64(total_damage_Array(count2)) + Convert.ToInt64(current_line.Substring(count3 + 4, count4 - (count3 + 4)))
total_damage_Array(count2) = total_damage
' The code around here checks previous line to see if it was a critical attack
' previous_line critical_hit critical_blast critical_undead
ElseIf current_line.Contains(display_name_Array(count2)) And display_name_Array(count2).ToString <> names_combo_box_Array(number_combo_index).ToString Then
total_damage = 0
End If
Next
' ******************************
Else
'Console.WriteLine("here")
End If
Next
Console.WriteLine("end")
' ===================================================================
' adds the data to the display grid, names, damage, duration, dps etc
Data_ParseTable.Rows.Clear()
For count1 = 0 To total_damage_Array.GetUpperBound(0)
If display_name_Array(count1) <> "" Then
Data_ParseTable.Rows.Add(display_name_Array(count1), Val(total_damage_Array(count1)))
End If
Next
Else ' parse a Player's toon- this is known because there is at least one space in the name.
Console.WriteLine("Parsing a player's toon")
End If
Else ' parse from time to time
Console.WriteLine("parsing time")
End If