In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Whether the error handling of VB.NET affects the running speed, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
When using any language for program development, we usually deal with the errors that will inevitably occur in the program development. Then in VB.NET, VB.NET error handling often has a certain impact on the running speed. On Error in VB.NET is used to catch and handle errors, and On Error Resume Next is often used to ignore errors that may occur.
So does the use of error trapping affect speed?
Yes, using VB.NET error handling will degrade some performance in. In Net, using Try Catch will also affect performance, so when we use Reflector to decompile Microsoft's class library, we will find that its subprocess rarely uses Try to catch errors, basically in a predictable way to judge possible errors and deal with them accordingly.
In fact, after using error trapping, the compiled code actually does a lot of operations that are not known to us. Although using error trapping facilitates the coding process to a certain extent, it sacrifices a certain speed, which has both advantages and disadvantages. So we should use error trapping correctly.
VB.NET tested
Option Explicit
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim m_FldsName () As String
Private Sub Command1_Click ()
Dim II As Long
Dim t As Single
Cn.Open "Provider=SQLOLEDB.1;Persist
Security Info=False;User ID=sa;Initial
Catalog= merchants; Data Source=SUPER "
Rs.Open "Select * from FldSet"
Cn, adOpenKeyset
Do Until rs.EOF = True
Rs.MoveNext
Loop
Rs.MoveFirst
T = Timer
ReDim m_FldsName (rs.Fields.Count)
For II = 0 To rs.Fields.Count-1
M_FldsName (II) = rs.Fields (II) .Name
Next
Do Until rs.EOF = True
ReadFieldsNotOnErr "Err1"
ReadFieldsNotOnErr "TableName"
ReadFieldsNotOnErr "Err2"
Rs.MoveNext
Loop
MsgBox "NotErr:" & Timer-t
On Error Resume Next
Rs.MoveFirst
T = Timer
Do Until rs.EOF = True
ReadFieldsOnErr "Err1"
ReadFieldsOnErr "TableName"
ReadFieldsOnErr "Err2"
Rs.MoveNext
Loop
MsgBox "OnErr:" & Timer-t
Rs.Close
Cn.Close
End Sub
Private Sub ReadFieldsOnErr
(FieldName As String)
Dim v As Variant
V = rs (FieldName) .Value
End Sub
Private Sub ReadFieldsNotOnErr
(FieldName As String)
Dim II As Long
Dim IsExists As Boolean
Dim v As Variant
IsExists = False
For II = 0 To UBound (m_FldsName)-1
If m_FldsName (II) = FieldName Then
IsExists = True
Exit For
End If
Next
If IsExists = True Then
V = rs (FieldName) .Value
End If
End Sub
Test results:
When there are no errors
ReadFieldsOnErr: 0 . 46 ReadFieldsNotOnErr: 0 . forty-seven
When there is a mistake
ReadFieldsOnErr: 0.96 ReadFieldsNotOnErr: 0.47
As you can see: without VB.NET error handling, the speed is quite stable, but when using VB.NET error handling, the speed drop is larger when there are errors. Therefore, for sub-procedures that are called frequently in the loop, it is recommended to preprocess the errors that may occur to reduce the use of On error to improve speed.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.