Hi all,
I've found and interesting article posted by Erel inside the "bugs & wishlist" section that deserves to be post in this section (and maybe as evidence article inside tutorials"). It deals about an interesting technique proposed to mimic references. This is the link http://www.b4x.com/forum/bugs-wishlist/8379-byref-parameter-android.html. I have investigated about the performances and I have discovered that references objects seem to be accessed in a faster way than primitive values. This is my profiling code. I got 3611 ticks with int variables and 3306 ticks with a reference object.
>>>> this is the log output ater two tests:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
by value 3611
by ref 3306
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
by value 3612
by ref 3576
I'm preparing a tutorial about references (now that I've understood how do the work - thanks to Erel and Agraham) sprites and easy linked gui-s
I've found and interesting article posted by Erel inside the "bugs & wishlist" section that deserves to be post in this section (and maybe as evidence article inside tutorials"). It deals about an interesting technique proposed to mimic references. This is the link http://www.b4x.com/forum/bugs-wishlist/8379-byref-parameter-android.html. I have investigated about the performances and I have discovered that references objects seem to be accessed in a faster way than primitive values. This is my profiling code. I got 3611 ticks with int variables and 3306 ticks with a reference object.
B4X:
Sub Globals
Dim a,k,m,n As Int : a=1
Dim start , Endt, diff As Int
Type brint (val As Int)
Dim b As brint : b.val=1
S2(a) ' call passing an int
S3(b) ' call passing and object containing an int
End Sub
Sub S2(x As Int )
start=DateTime.Now
For n=1 To 1000
For k=1 To 1000
m=x/2 ' direct use of x
Next
Next
diff=DateTime.Now-start
Log("by value " &diff)
End Sub
Sub S3(x As brint )
start=DateTime.Now
For n=1 To 1000
For k=1 To 1000
m=x.val/2 'indirect use of the value through the Object
Next
Next
diff=DateTime.Now-start
Log("by ref " & diff)
End Sub
>>>> this is the log output ater two tests:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
by value 3611
by ref 3306
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
by value 3612
by ref 3576
I'm preparing a tutorial about references (now that I've understood how do the work - thanks to Erel and Agraham) sprites and easy linked gui-s