Hi,
last week I tried to compare the B4J performances against Python 3.11 in executing the classic Fibonacci number recursive implementation. here's the code I have used for both cases.
Edit: below the correct B4J code. in the original post I missed to specify the parameter type so string was used...
B4J:
Python:
Of course the test is performed on the same pc (my pc, i7 2.8Ghz, 16Gb Ram).
For B4J I am using 9.8 (64bit) version.
For python I have used Pycharm 2022.2.3 configured to use Python 3.11 as interpreter.
here's the results:
EDIT (new numbers after correcting my code mistake in original post)
B4J: ~0.2 sec (with console app it goes down to 0.13)
Python; ~ 6 sec
Is this an expected result or am I making something wrong in the comparison?
thanks and happy new year!
last week I tried to compare the B4J performances against Python 3.11 in executing the classic Fibonacci number recursive implementation. here's the code I have used for both cases.
Edit: below the correct B4J code. in the original post I missed to specify the parameter type so string was used...
B4J:
B4X:
Sub fib(n as long) As Long
If n <= 1 Then
Return n
Else
Return (fib(n-1)+fib(n-2))
End If
End Sub
B4X:
Sub Button1_Click
'xui.MsgboxAsync("Hello World!", "B4X")
Dim ExecTime As Long, ff As Float
Dim fiblong As Long
ExecTime = DateTime.Now
fiblong = fib(38)
ExecTime = (DateTime.Now-ExecTime) '/1000
Log(fiblong)
Log(ExecTime)
ff = ExecTime/1000
Label1.Text = ff
End Sub
Python:
Python:
import time
def fib(n):
if n <= 1:
return n
else:
return (fib(n-1)+fib(n-2))
st = time.time()
print(fib(38))
et = time.time()
elapsed = et - st
print('Exec time:',elapsed,'seconds')
Of course the test is performed on the same pc (my pc, i7 2.8Ghz, 16Gb Ram).
For B4J I am using 9.8 (64bit) version.
For python I have used Pycharm 2022.2.3 configured to use Python 3.11 as interpreter.
here's the results:
EDIT (new numbers after correcting my code mistake in original post)
B4J: ~0.2 sec (with console app it goes down to 0.13)
Python; ~ 6 sec
Is this an expected result or am I making something wrong in the comparison?
thanks and happy new year!
Last edited: