Sub Button1_Click
xui.MsgboxAsync("Hello World!", "B4X")
Dim jo As JavaObject = Me
Dim start, stop, loopCount As Long
loopCount = 100000000
Log($"Executing B4X's "integer" division ${loopCount} times"$)
start = DateTime.Now
b4xIntDiv(5, 7, loopCount)
stop = DateTime.Now
Log($"b4xIntDiv took ${stop-start} ticks to complete ${loopCount} operations"$)
Log($"Executing Java's integer division ${loopCount} times"$)
start = DateTime.Now
jo.RunMethod("JavaIntDiv", Array(5, 7, loopCount))
stop = DateTime.Now
Log($"Java took ${stop-start} ticks to complete ${loopCount} operations"$)
End Sub
'Executing B4X's "integer" division 100000000 times
'b4xIntDiv took 363 ticks To complete 100000000 operations
'Executing Java's integer division 100000000 times
'Java took 116 ticks To complete 100000000 operations
public Sub b4xIntDiv(a As Int, b As Int, loopCount As Long) As Int
Dim result As Int
Dim counter As Long
Do While counter < loopCount
a = a + 1 '<== added this
b = b + 1 '<== added this
result = a / b
counter = counter + 1
Loop
Return result
End Sub
#IF JAVA
public static int JavaIntDiv (int a, int b, long loopCount){
int result = 0;
for (long counter=0; counter < loopCount; counter++) {
a++; '<== added this
b++; '<== added this
result = a / b;
}
return result;
}
#End If