[Gambas-user] trimming extra spaces from within a string.

Martin mbelmonte at belmotek.net
Tue Nov 10 17:10:20 CET 2020


Oliver, you right, your method is faster that others.

Here I attach an screen shot of profiler and also the sample project for 
testing.

Testing using Fast unsafe

Regards.

On 10/11/20 16:47, Linus via User wrote:
> Hi,
>
> Just a question, why not just use SPLIT function to split all the text 
> and next reassemble it by a JOIN
>
> Public Sub TrimText(sText As String)
>
>   Dim aText As String[]
>
>   atext = Split(sText, " ", Chr(140), True)
>
>   Print atext.Join(" ")
>
> End
>
>
> Too simple maybe
>
>
> Olivier
>
>> Le 10 nov. 2020 à 06:45, Rolf-Werner Eilert <rwe-sse at osnanet.de 
>> <mailto:rwe-sse at osnanet.de>> a écrit :
>>
>> Am 10.11.20 um 12:28 schrieb Christof Thalhofer:
>>> Am 10.11.20 um 11:56 schrieb Rolf-Werner Eilert:
>>>> Your race was a bit about speed. Using Replace() over and over might be
>>>> the drawback here, as it will certainly use a loop internally doing 
>>>> more
>>>> or less the same as my function does. The same applies to regex, and
>>>> even heavier.
>>>>
>>>> But I agree, the other solutions are more elegant than mine :)
>>> Currently Brian G holds the price for max speed.
>>> And yours needs about 1600 ms for one single(!) run* of the bobiba.txt
>>> on my computer. I think it's one of the slowest. ;-)
>>> The other ones run the text 500 times in about 2.5 seconds. Your code
>>> would need about 13 minutes for the same task.
>>
>> Wow that's impressive. What is the reason? I would guess that 
>> compiled C-code is always faster than interpreted code, even if the 
>> function is more complex.
>>
>>> Alles Gute
>>
>> Dir auch :)
>>
>> Rolf
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201110/181438dd/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-with-fast-unsafe.png
Type: image/png
Size: 56133 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201110/181438dd/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sample-trim-faster-0.0.3.tar.gz
Type: application/gzip
Size: 12323 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201110/181438dd/attachment-0001.gz>


More information about the User mailing list