Is there more overhead to code in a single statement then to break it down
step by step?
I'm relatively new to VB.NET and am self taught in programming so I am
without a lot of foundation knowledge and concepts so please excuse my
naivety and ignorance.
I am curious about the logistics, performance, and efficiency of writing
VB functions step by step or just in one long line of code.
The following is a small function from one of my programs to parse some
HTML. Please note that code is just a random example and both blocks of
code perform exactly the same functions. They are here to illustrate my
point of long, procedural declared, segmented etc. code in contrast with
one long concise piece of code, respectively.
Long code
Dim html As String
Dim htmlString As String
Dim dIndex As Integer
html = WebBrowser.DocumentText
htmlString = "size=" & Chr(34) & "15" & Chr(34) & " maxlength=" & Chr(34)
& "40" & Chr(34) & ">"
dIndex = html.IndexOf(htmlString)
If (dIndex > -1) Then
Dim lIndex As Integer
Dim sDomain As String
sDomain = html.Substring(dIndex + 26, 20)
lIndex = sDomain.IndexOf("<")
LblSubDomain.Text = sDomain.Substring(0, lIndex)
Else
LblSubDomain.Text = "Cannot Find Sub Domain Extension"
End If
Short code
If (WebBrowser.DocumentText.IndexOf("size=" & Chr(34) & "15" & Chr(34) & "
maxlength=" & Chr(34) & "40" & Chr(34) & ">") > -1) Then
LblSubDomain.Text =
WebBrowser.DocumentText.Substring(WebBrowser.DocumentText.IndexOf("size="
& Chr(34) & "15" & Chr(34) & " maxlength=" & Chr(34) & "40" & Chr(34)
& ">") + 26, 20).Substring(0,
WebBrowser.DocumentText.Substring(WebBrowser.DocumentText.IndexOf("size="
& Chr(34) & "15" & Chr(34) & " maxlength=" & Chr(34) & "40" & Chr(34)
& ">") + 26, 20).IndexOf("<"))
Else
LblSubDomain.Text = "Cannot Find Sub Domain Extension"
End If
My question is: Which of the two blocks of code will have the least impact
on performance or does VB2012 compile it to one line of code so that it
makes no difference?
Thank you guys so much and I hope my question falls within the scope of
expectations of Stack Overflow
No comments:
Post a Comment