Let's say you have a lot of For/Next cycles going on and you desperately need to improve your computing speed. What would you do?
I came up with this idea, reducing all the cycles into a single one.
Would this be a good technique?
Before:
After:
I came up with this idea, reducing all the cycles into a single one.
Would this be a good technique?
Before:
B4X:
Sub Whatever(Value as int)
...
'Do Stuff
...
End Sub
Sub Example
Dim array_x(512)
Dim array_y(1024)
Dim array_z(256)
Populate_Array(x)
Populate_Array(y)
Populate_Array(z)
For i = 0 to (array_x.Lenght - 1)
Whatever(array_x(i))
Next
For i = 0 to (array_y.Lenght - 1)
Whatever(array_y(i))
Next
For i = 0 to (array_z.Lenght - 1)
Whatever(array_z(i))
Next
End Sub
After:
B4X:
Sub Whatever(Value as int)
...
'Do Stuff
...
End Sub
Sub Example
Dim array_x(512)
Dim array_y(1024)
Dim array_z(256)
Populate_Array(x)
Populate_Array(y)
Populate_Array(z)
For i = 0 to (Max(array_x.Lenght, Max(array_y.Lenght, array_z.Lenght)) - 1)
Select True
Case i < array_x.Lenght
whatever(array_x(i))
Case i < array_y.Lenght
whatever(array_y(i))
Case i < array_z.Lenght
whatever(array_z(i))
End Select
Next
End Sub