Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stop Non-numeric strings from crashing the server.
#10
Testing IsNumeric vs my method. 10000 loops.

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
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)