Good morning everyone.
I have a problem that only occurs with b4i.
I have a txt file that contains 3500 lines, in which I should search for an item that can be present multiple times. so I should find a method to search for all the desired items within this file. I tried readlist (but the file is too big and becomes slow)..can anyone give me some advice? A thousand thanks
unfortunately I have to use txt (customer need) and I can't use sql
#if b4a
Dim fileindice As List = File.ReadList(File.DirInternal,"indicec.txt")
#else
Dim fileindice As List = File.ReadList(File.DirDocuments,"indicec.txt")
#End If
Dim nome As String
Dim nome2 As String
'listapdf = fileindice
For i = 0 To fileindice.Size-1
nome = fileindice.Get(i)
If nome.Contains(globe.tesseraperserver) And globe.tesseraperserver <> "" Then
globe.contindice = globe.contindice+1
Else
nome2=nome2
End If
Next
in this simple cycle, on Android it is very fast, on iOS it takes up to 6/7 seconds
I'm doing a simple thing, I'm looking for a certain number within the list that I created by reading the file.
what could I have done wrong?
For i = 0 To fileindice.Size-1
nome = fileindice.Get(i)
If nome.Contains(globe.tesseraperserver) And globe.tesseraperserver <> "" Then
globe.contindice = globe.contindice+1
Else
nome2=nome2
End If
Next
Well, maybe I'm not seeing something, but the first two changes I'd make are:
1/ hoist the empty-string check out of the loop (should be ok, as long as you're not later relying on nome being the last list item)
2/ remove the nome2 = nome2 (unless this is a typo, maybe it's meant to be nome2 = nome)
example:
If globe.tesseraperserver <> "" Then
For i = 0 To fileindice.Size - 1
nome = fileindice.Get(i)
If nome.Contains(globe.tesseraperserver) Then
globe.contindice = globe.contindice + 1
End If
Next
End If
and then I'd check that the delay is indeed in this section of your looks-ok-to-me code, by adding:
example:
Dim StartTime As Long = DateTime.Now
If globe.tesseraperserver <> "" Then
For i = 0 To fileindice.Size - 1
nome = fileindice.Get(i)
If nome.Contains(globe.tesseraperserver) Then
globe.contindice = globe.contindice + 1
End If
Next
End If
Dim EndTime As Long = DateTime.Now
Log("Search took " & (EndTime - StartTime) & " milliseconds")
and then I'd check that the delay is indeed in this section of your looks-ok-to-me code, by adding:
example:
Dim StartTime As Long = DateTime.Now
If globe.tesseraperserver <> "" Then
For i = 0 To fileindice.Size - 1
nome = fileindice.Get(i)
If nome.Contains(globe.tesseraperserver) Then
globe.contindice = globe.contindice + 1
End If
Next
End If
Dim EndTime As Long = DateTime.Now
Log("Search took " & (EndTime - StartTime) & " milliseconds")
for searching 3500 lines of 60..65 characters, I agree
next tack:
example:
Dim StartTime As Long = DateTime.Now
If globe.tesseraperserver <> "" Then
For i = 0 To fileindice.Size - 1
nome = fileindice.Get(i)
If i < 10 Then Log(fileindice.size & Tab & i & Tab & (DateTime.Now - StartTime) & Tab & "[" & nome & "]")
If nome.Contains(globe.tesseraperserver) Then
globe.contindice = globe.contindice + 1
End If
Next
End If
Dim EndTime As Long = DateTime.Now
Log("Search took " & (EndTime - StartTime) & " milliseconds")
for searching 3500 lines of 60..65 characters, I agree
next tack:
example:
Dim StartTime As Long = DateTime.Now
If globe.tesseraperserver <> "" Then
For i = 0 To fileindice.Size - 1
nome = fileindice.Get(i)
If i < 10 Then Log(fileindice.size & Tab & i & Tab & (DateTime.Now - StartTime) & Tab & "[" & nome & "]")
If nome.Contains(globe.tesseraperserver) Then
globe.contindice = globe.contindice + 1
End If
Next
End If
Dim EndTime As Long = DateTime.Now
Log("Search took " & (EndTime - StartTime) & " milliseconds")
the only potential difference I can imagine is that the string handling is different between B4A and B4I
perhaps it is creating and allocating new memory each loop at the nome = fileindice.Get(i) line
and then maybe it is even slower in debug mode
so perhaps try:
example:
Dim StartTime As Long = DateTime.Now
If globe.tesseraperserver <> "" Then
For i = 0 To fileindice.Size - 1
''' nome = fileindice.Get(i)
''' If i < 10 Then Log(fileindice.size & Tab & i & Tab & (DateTime.Now - StartTime) & Tab & "[" & nome & "]")
''' If nome.Contains(globe.tesseraperserver) Then
If fileindice.Get(i).As(String).Contains(globe.tesseraperserver) Then
globe.contindice = globe.contindice + 1
End If
Next
End If
Dim EndTime As Long = DateTime.Now
Log("Search took " & (EndTime - StartTime) & " milliseconds")
the only potential difference I can imagine is that the string handling is different between B4A and B4I
perhaps it is creating and allocating new memory each loop at the nome = fileindice.Get(i) line
and then maybe it is even slower in debug mode
so perhaps try:
example:
Dim StartTime As Long = DateTime.Now
If globe.tesseraperserver <> "" Then
For i = 0 To fileindice.Size - 1
''' nome = fileindice.Get(i)
''' If i < 10 Then Log(fileindice.size & Tab & i & Tab & (DateTime.Now - StartTime) & Tab & "[" & nome & "]")
''' If nome.Contains(globe.tesseraperserver) Then
If fileindice.Get(i).As(String).Contains(globe.tesseraperserver) Then
globe.contindice = globe.contindice + 1
End If
Next
End If
Dim EndTime As Long = DateTime.Now
Log("Search took " & (EndTime - StartTime) & " milliseconds")
Is your program updating any status information on screen during the search, eg a live count of how many matches found, or how many records searched?
It might be that Android only redraws the screen pixels once per frame ie 60 times a second, and that iOS might redraw the screen pixels each time you update the status value, even if the value is the same as before.
Again, still clutching at straws if anybody else has better ideas, then feel free to join in
Is your program updating any status information on screen during the search, eg a live count of how many matches found, or how many records searched?
It might be that Android only redraws the screen pixels once per frame ie 60 times a second, and that iOS might redraw the screen pixels each time you update the status value, even if the value is the same as before.
Again, still clutching at straws if anybody else has better ideas, then feel free to join in
So I tried to evaluate it again in release mode with your latest suggestions and damn, the problem does NOT arise!! amazing! why did it cause me so many problems while debugging?? I am tired