Private Declare Function GetTickCount& Lib "kernel32" ()
Private Sub BenchMark()
Dim sString1 As String, sString2 As String, lStart As Long, lEnd As Long, sOut As String
sString1 = RandomString(2000)
sString2 = RandomChanges(sString1, 10, 10, 5)
Debug.Print sString1
Debug.Print sString2
lStart = GetTickCount
sOut = SeekMatch(sString1, sString2)
lEnd = GetTickCount
Debug.Print sOut
Debug.Print lEnd - lStart
End Sub
Private Function RandomString(lChars As Long) As String
Dim lCount As Long, bTemp() As Byte
ReDim bTemp(lChars)
For lCount = LBound(bTemp) To UBound(bTemp)
bTemp(lCount) = Rand(33, 126)
Next lCount
RandomString = StrConv(bTemp, vbUnicode)
End Function
Private Function RandomChanges(ByVal sString As String, lInserts As Long, lDeletes As Long, _
Optional lBoundry As Long = 10) As String
Dim lCount As Long, sOut As String, lStart As Long, lEnd As Long, sInsert As String, lLen As Long
Dim sLeft As String, sRight As String, lTemp As Long
For lCount = 1 To lInserts
lLen = Len(sString)
lStart = Rand(1, lLen)
sInsert = RandomString(Rand(1, lBoundry))
If lStart = 0 Then
sString = sInsert & sString
ElseIf lStart = lLen Then
sString = sString & sInsert
Else
sLeft = Left$(sString, lStart)
sRight = Right$(sString, lLen - lStart)
sString = sLeft & sInsert & sRight
End If
Next lCount
For lCount = 1 To lDeletes
lLen = Len(sString)
lStart = Rand(1, lLen)
If lStart + lBoundry > lLen Then
lEnd = lLen
Else
lEnd = Rand(lStart, lStart + lBoundry)
End If
If lStart = 1 And lEnd = lLen Then
sString = vbNullString
Exit For
End If
If lEnd = lLen Then
sString = Left$(sString, lStart - 1)
ElseIf lStart = 1 Then
sString = Right$(sString, lLen - lEnd)
Else
sLeft = Left$(sString, lStart - 1)
sRight = Right$(sString, lLen - lEnd)
sString = sLeft & sRight
End If
Next lCount
RandomChanges = sString
End Function
Private Function Rand(lLow As Long, lHigh As Long) As Long
Rand = Int((lHigh - lLow + 1) * Rnd + lLow)
End Function