I am wondering which is more efficient, using CStr() or object.toString(). The reason I ask this is because I though all that CStr() done was to invoke the .ToString() metho
I tried to time the following two subroutines (forgive my variable naming):
For i As Integer = 1 To 1000
For j As Integer = 1 To 65536
eee = aaa.ToString()
eee = bbb.ToString()
eee = ccc.ToString()
eee = ffffd.ToString()
eee = Nothing
Next
Next
and
For i As Integer = 1 To 1000
For j As Integer = 1 To 65536
eee = CStr(aaa)
eee = CStr(bbb)
eee = CStr(ccc)
eee = CStr(ffffd)
eee = Nothing
Next
Next
where
Dim aaa As Integer = 1233
Dim bbb As Single = 445.234234234
Dim ccc As Double = 234234.234457634
Dim ffffd As Decimal = 1231.3466734523424
Dim eee As String = Nothing
the ToString()
loop takes 62 seconds and the CStr()
loop takes 64 seconds. It is really not a huge impact in my opinion, if you are only dealing with numbers. I disabled any compiler optimization during the timing process.