09-04-2009, 12:22 PM
Testing IsNumeric vs my method. 10000 loops.
There's only a 1 millisecond difference, but that's still something.
Test1:
Test2:
I use Spodis' speed template for testing: http://www.vbgore.com/Testing_VB_code_speed
Quote:%Faster -40| -25| -25| -25| -25| 33.3| -25| -25| 0| -25
Test1 3| 3| 3| 3| 3| 4| 3| 3| 4| 3
Test2 5| 4| 4| 4| 4| 3| 4| 4| 4| 4
There's only a 1 millisecond difference, but that's still something.
Test1:
Code:
Public Sub TestOne()
CCInt "test1"
End Sub
Private Function CCInt(ByRef s As String) As Integer
If LenB(s) = 0 Then Exit Function
If Not s Like "*[!0-9]*" Then CCInt = CInt(s)
End Function
Test2:
Code:
Public Sub TestTwo()
CCInt "test2"
End Sub
Private Function CCInt(ByRef s As String) As Integer
If LenB(s) = 0 Then Exit Function
If IsNumeric(s) Then CCInt = CInt(s)
End Function
I use Spodis' speed template for testing: http://www.vbgore.com/Testing_VB_code_speed