I've just tried it with very simple 1 value types and it takes 1 ms to run through 302 values on a Samsung j330:
B4X:
Type T1(Val As Object)
Type T2(Val As Object)
B4X:
Dim L As List
L.Initialize
For i = 0 To 150
Dim T As T1
T.Initialize
T.Val = i
L.Add(T)
Dim TY2 As T2
TY2.Initialize
TY2.Val = i
L.Add(TY2)
Next
Dim T1Count, T2Count As Int
Dim StartTime As Long = DateTime.Now
For Each O As Object In L
If O Is T1 Then
T1Count = T1Count + 1
Else
T2Count = T2Count + 1
End If
Next
Log("Time = " & (DateTime.Now - StartTime))
Log(T1Count)
Log(T2Count)
Are the types complex? or is the code doing anything major within the loop?
I've just tried it with very simple 1 value types and it takes 1 ms to run through 302 values on a Samsung j330:
B4X:
Type T1(Val As Object)
Type T2(Val As Object)
B4X:
Dim L As List
L.Initialize
For i = 0 To 150
Dim T As T1
T.Initialize
T.Val = i
L.Add(T)
Dim TY2 As T2
TY2.Initialize
TY2.Val = i
L.Add(TY2)
Next
Dim T1Count, T2Count As Int
Dim StartTime As Long = DateTime.Now
For Each O As Object In L
If O Is T1 Then
T1Count = T1Count + 1
Else
T2Count = T2Count + 1
End If
Next
Log("Time = " & (DateTime.Now - StartTime))
Log(T1Count)
Log(T2Count)
Are the types complex? or is the code doing anything major within the loop?
Type shopitem(id As Int,description As String, category As String, unit As String, quantity As Float, price As Double, note As String, status As Int, favorite As Boolean) 'status 0 = to buy, 1 = bought, 2 = doesnot exist
after some research i found that going through KVS db is maybe the reason it takes so long so what i do is i copy on activity_create all items to a map and then go through that map instead of the KVS map and it takes much faster.
from 220-250ms i went down to 10-15ms
the kvs stores such types in it and it seems for me that checking if an object is a type take longer then just go through a loop without such a check but the main reason it took so long was using the kvs instead of a simple map.