Poor Performance in Visual Studio
Hi,
I am an experienced VB6 programmer, but just a new starter in Visual Studio 2005.
I have found Visual Studio 2005 to be very slow. I set up 3 simple tests with the following results:-
1. Scanning 20,000 directory entries and
retrieving date/time and size info
VB6
3
Secs
Visual Studio (Debug)13
secs
Visual Studio (exe) 3
Secs
2. loading 100,000 Nodes
into a treeview
VB6
2 secs
Visual Studio (Debug)320
secs
Visual Studio (exe)140
secs
3. loading 100,000
Itemsinto a Listview
VB62 secs 11 secs
Visual Studio (Debug)270
Secs
Visual Studio (exe)200
secs
I realise these are not something you do every day, but performance hits of up to 100 is pretty high.
I am not sure whether this is just a
feature of Visual Studio, whether my coding is poor, whether I
have inadvertantly set some funny debug options, or whether my PC is just too old to handle it.
Any comments on other experiences, or where I should go to find some info?
(Apologies if this is a dumb question, or if I have posted it in the wrong group)
Alan Cuthbertson
Thanks for the feed back.
I tried turning of the Overflow checking, but no change.
Tried running the tests several times and the results were all consistent
I did some fiddling and was able to get the Treeview load
working better (3 secs in VB, 10 secs in Visual Studio (compiled) , 43 secs in
Visual Studio IDE.
Also found I could speed up the Listview ADD command
significantly by removing the line that added a SubItem. (6 secs for VB6, 10
secs Visual Studio (compiled), 20 secs Visual Studio IDE. Presumably there is a
more efficient way of doing this?
itemx = ListView1.Items.Add("AAA")
itemx.SubItems.Insert(1, New
System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "BBBB"))
As a general question, do you normally find the IDE takes
twice as long as compiled? VB6 always seemed about the same speed,
Here is the code I used for adding the Listview:-
VB6
Private Sub Command3_Click()
Dim itemx As ListItem
Dim I As Long
Dim TimeStore As Double
ListView1.ListItems.Clear
TimeStore = Now
For I = 1 To 100000
Set itemx = ListView1.ListItems.Add
itemx.Text = "AAA"
itemx.SubItems(1) = "BBB"
Next I
Screen.MousePointer = 0
MsgBox "Start:" + Format$(TimeStore, "HH:MM:SS") + Chr$(13) + "Finish:" + Format$(Now, "HH:MM:SS")
End Sub
Visual Studio
Private Sub Command3_Click(ByVal eventSender As
System.Object, ByVal eventArgs As System.EventArgs) Handles
Command3.Click
Dim itemx As System.Windows.Forms.ListViewItem
Dim I As Long
Dim TimeStore As Double
ListView1.Items.Clear()
TimeStore = Now.ToOADate
For I = 1 To 100000
itemx = ListView1.Items.Add("AAA")
itemx.SubItems.Insert(1, New
System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "BBBB"))
Next I
MsgBox("Start:" &
VB6.Format(TimeStore, "HH:MM:SS") & Chr(13) & "Finish:" &
VB6.Format(Now, "HH:MM:SS"))
End Sub
I
reran the test and got 6 secs for VB6, 264 secs for Visual Studio in the IDE,
230 secs when compiled.
I
then tried commenting out the Line:-
itemx.SubItems.Insert(1,New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "BBBB")),
And
run tme dropped to 20 secs in the IDE, 10 secs when Compiled. BIG IMPROVEMENT,
but not perfect, so is there a better way to add a subitem? (as I said, I am a
VB6 programmer and relied on the Conversion wizard to generate the code)
Code
for the TreeView Add (adds 10
nodes, each node has 6 children, extending down a depth of 6. Close to 100,000
nodes):-
VB6
Private Sub Command2_Click()
Dim I As Long
Dim Basenode As Node
Dim Newnode As Node
Dim TimeStore As Double
TreeView1.Nodes.Clear
TimeStore = Now
Set Basenode = TreeView1.Nodes.Add()
Basenode.Text = "root"
Basenode.Expanded = True
For I = 1 To 10
Set Newnode = TreeView1.Nodes.Add(Basenode, tvwChild)
Newnode.Text = "AAA"
Call AddBranch(Newnode, 1)
Next I
MsgBox "Start:" + Format$(TimeStore, "HH:MM:SS") + Chr$(13) + "Finish:" + Format$(Now, "HH:MM:SS")
End Sub
Sub AddBranch(Node As Node, depth)
Dim I As Integer
Dim Newnode As Node
If depth > 6 Then
Exit Sub
End If
Set Newnode = TreeView1.Nodes.Add(Node, tvwChild)
Newnode.Text = "BBB"
For I = 1 To 6
Call AddBranch(Newnode, depth + 1)
Next I
End Sub
Visual Studio
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
Dim I As Long
Dim Basenode As System.Windows.Forms.TreeNode
Dim Newnode As System.Windows.Forms.TreeNode
Dim TimeStore As Double
TreeView1.Nodes.Clear()
TimeStore = Now.ToOADate
Basenode = TreeView1.Nodes.Add("")
Basenode.Text = "root"
Basenode.Expand()
For I = 1 To 10
Newnode = Basenode.Nodes.Add("")
Newnode.Text = "AAA"
Call AddBranch(Newnode, 1)
Next I
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default
MsgBox("Start:" &
VB6.Format(TimeStore, "HH:MM:SS") & Chr(13) & "Finish:" &
VB6.Format(Now, "HH:MM:SS"))
End Sub
Sub AddBranch(ByRef Node As System.Windows.Forms.TreeNode, ByRef depth As Long)
Dim I As Short
Dim Newnode As System.Windows.Forms.TreeNode
If depth > 6 Then
Exit Sub
End If
Newnode = Node.Nodes.Add("BBB")
For I = 1 To 6
Call AddBranch(Newnode, depth + 1)
Next I
End Sub
Brilliant! That works like a dream!
The only thing is, that I would never have thought of it myself. Would
this be common knowledge to anyone who knew what they were doing in
Visual Studio (i.e had been on a course) , or do you have to be a guru?
I also found out in playing that using
Newnode = Node.Nodes.Add("BBB")
is far quicker than
Newnode = Node.Nodes.Add("")
Newnode.text = "BBB"
especially when there are lots of nodes
Once again is this obvious to those experienced in Visual Studio? Is it doing a search of the nodes or something?
Also tried the Range suggestion for Nodes:-
Dim x() As TreeNode = New TreeNode(5) {}
For I = 0 To 5
x(I) = New TreeNode("AAAA")
Next I
Node.Nodes.AddRange(x)
For I = 0 To 5
Call AddBranch(x(I), depth + 1)
Next I
but that even ran slower...