[Gambas-user] '&=' operator optimization

Jussi Lahtinen jussi.lahtinen at gmail.com
Sat Apr 4 18:58:45 CEST 2020


Current code fails in GambasTester. Could be due earlier bug.
I highly recommend to automatically run it after compilation. I know it's
ugly as hell, but it does its job a lot better than nothing.

Jussi

On Sat, Apr 4, 2020 at 5:32 PM Benoît Minisini <g4mba5 at gmail.com> wrote:

> 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
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200404/ed23a199/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GambasTestercmd-0.10.22.tar.gz
Type: application/gzip
Size: 30027 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20200404/ed23a199/attachment-0001.gz>


More information about the User mailing list