Results 1 to 40 of 59

Thread: [RESOLVED] multiple range checking algorithm vb6

Threaded View

  1. #28
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    928

    Re: multiple range checking algorithm vb6

    Quote Originally Posted by Schmidt View Post
    Well, then let's see what your recommendations will bring, when I alter it to your wishes...


    Ok, done...


    ... as you wish, master...


    Please forgive me, but I've found it this way in posting #10 (from a guy named "flyguille")...
    But Ok - I've adapted it now as commanded...



    I hope the new code below is to your satisfaction now - but I have to tell you that the changes you demanded,
    make it now run factor 2 slower than before... (about 3.3 µsec per call, compared to the former 1.6)
    What now?

    Wouldn't it be better, when you perhaps write "the ideal code" for the usage of your approach yourself -
    and post it here (preferrably within Code-Tags, if that's not too much to ask...).

    Code:
    Option Explicit
    
    Private LookupTable(0 To 255, 0 To 255, 0 To 255, 0 To 31) As Byte
    
    Private Sub Form_Click()
      Dim i As Long, Result As Boolean, T As Single
      T = Timer
        For i = 1 To 100000
          Result = IsInUSA("121.122.123.124")
          If Result Then
            'do something here
          End If
        Next
      Caption = Format$((Timer - T) * 10, "0.0") & " µSec per function-call"
    End Sub
    
    Function IsInUSA(RemoteIP As String) As Boolean
      Dim st() As String
          st = Split(RemoteIP, ".")
    
      IsInUSA = LookupTable(Val(st(0)), Val(st(1)), Val(st(2)), Int(Val(st(3)) / 16) And (Val(st(3)) Mod 16))
    End Function
    Olaf
    ok remove the INT(), btw I didn't know a Split() function, is slower than 7 VB string function which its parameters parsings and all. weird.

    oh, BTW? why you chose MOD and / 16, if it is 8 , as per 8 bits per byte?

    oh, and you didn't did the BIT inspection, just readed the whole byte as output!.

    lets change the: To 31

    Private LookupTable(0 To 255, 0 To 255, 0 To 255, 0 To 31) As Byte

    and

    IsInUSA = LookupTable(Val(st(0)), Val(st(1)), Val(st(2)), Val(st(3)), Val(st(4)) / 8) And (2^(Val(st(4)) Mod 8)

    oh, now I see you didn't inspect the fourth value at all!

    Ofcourse now it is a bit slower.

    But prefferably a lookup table, and not rolling an array with many entries, including it doing binary search would be slower.

    Oh, BTW, thanks by your participation.
    Last edited by flyguille; Aug 20th, 2017 at 09:30 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width