From the performance view, is it better to check or not to check for Nothing(null) before set it?
Is clear that for readability maybe there is no need of supplementary step, but for performance? Maybe testing the IF is less time consuming that setting to NULL, if there is no need of?!
I run that on a computer, and the result was the same.
Dim sw As New Stopwatch()
sw.Start()
For i As Integer = 0 To 10000
_MyObject = Nothing
Next
sw.Stop()
Console.WriteLine("no check: {0}", sw.Elapsed)
sw.Reset()
sw.Start()
For i As Integer = 0 To 10000
If _MyObject IsNot Nothing Then
_MyObject = Nothing
End If
Next
sw.Stop()
Console.WriteLine("with check: {0}", sw.Elapsed)
Result:
no check: 00:00:00.0000326
with check: 00:00:00.0000349