[Gambas-user] '&=' operator optimization

Benoît Minisini g4mba5 at gmail.com
Sat Apr 4 16:30:55 CEST 2020


Hi,

In the last commit, I implemented an optimization of a common usage 
pattern of the '&=' operator, where a string is actually used as an 
accumulation buffer.

Look at the following code, where a global string is filled with 
arbitrary strings:

Private $sBuffer As String

Public Sub Main()

   Dim I As Integer
   Dim C As String
   Dim J As Integer
   Dim T As Float

   T = Timer
   For I = 1 To 10000
     For J = 65 To 90
       C = Chr$(J)
       $sBuffer &= ".(" & C & ")"
     Next
   Next

   Print Len($sBuffer);; Timer - T

End

Before the optimization, that code runs in about 6.64 seconds.

After the optimization, it runs in 0.026 seconds. More than 250 times 
faster!

Note that the optimization works only if the string buffer is a local or 
global variable.

If you detect any problem or any crash with that optimization, tell me.

Regards,

-- 
Benoît Minisini


More information about the User mailing list