Can you post your algorithm code?
Here it is. It's kind of long. The list in the outer loop has 175,000 (175 thousand) words of less than 10 characters. The inner two loops also have words of less than 10 characters. I left in my crude profiling code (tr stuff).
On my 1 GHz Vibrant, I get the following timing:
tr(2) = 127 secs
tr(3) = 107 secs
tr(4) = 35 secs
The most inner loop, tr(4), is not too bad. The middle loop minus the most inner loop, tr(3)-tr(4), must be 72 secs. this seems to be the culprit. The most outer loop minus the middle, tr(2)-tr(3), loop is 20 secs.
I have tried your trick for using ByRef in the statements that call RemLet, but that actually increased the time a little. I got the same answer so I have some confidence that I actually did it right.
Instead of a list to hold 175,000 words, at first I used a database. Using a list is quite a bit faster.
Thanks,
Barry.
tr(2).srt = DateTime.Now
For i=0 To ScrList.Size-1 ' for each list word
If (i Mod 1000 = 0) Then ' update progressbar
k = 2 + 98 * (i/ScrList.Size)
pbrPB1.Progress = k
End If
DoEvents
If (fSrchCancel = True) Then
PgShow = 0
pnlSwap(pnlMain, pnlMain)
Return
End If
s = ScrList.Get(i)
s = s.ToUpperCase
l = s.Length
tr(3).srt = DateTime.Now
For j=0 To l2-1 ' for each let match check if it has remainder
ts = s ' temp word
p1 = ts.IndexOf(s2.CharAt(j))
If (p1 >= 0) Then
ts = RemLet(ts, p1) ' remove first occurrence of let form word
Else
Continue ' try next let. word must have let
End If
fmtch = True
ts1 = s1 ' temp letters
tr(4).srt = DateTime.Now
For k=0 To ts.Length-1 ' check if each let of temp word is in letters
p1 = ts1.IndexOf(ts.CharAt(k))
If (p1 >= 0) Then
RemLet(ts1, p1) ' letter used in match
Else
fmtch = False
Exit ' word let not in letters
End If
Next
tr(4).end = DateTime.Now
tr(4).tot = tr(4).tot + (tr(4).end - tr(4).srt)
If (fmtch = True) Then ' add word to results table
v(0) = ScrList.Get(i)
v(1) = ScoreWord(v(0))
v(2) = v(0).Length
SQL1.ExecNonQuery2("INSERT INTO restmp (mword, mscore, mlen) VALUES (?, ?, ?)", v)
End If
Next
tr(3).end = DateTime.Now
tr(3).tot = tr(3).tot + (tr(3).end - tr(3).srt)
Next ' next word
tr(2).tot = DateTime.Now - tr(2).srt
Log("*** tr2 = " & tr(2).tot)
Log("*** tr3 = " & tr(3).tot)
Log("*** tr4 = " & tr(4).tot)
End If
Sub RemLet(str As String, pos As Int) As String
Dim l As Int
Dim s, t As String
l = str.Length
s = str
If (l <= 1) Then
t = ""
Else
If (pos >= l) Then
t = s
Else
If (pos = 0) Then
t = s.SubString(1)
Else
If (pos = l-1) Then
t = s.SubString2(0, l-1)
Else
t = s.SubString2(0, pos) & s.SubString(pos+1)
End If
End If
End If
End If
Return t
End Sub