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

Brian G brian at westwoodsvcs.com
Tue Nov 10 17:50:43 CET 2020


Martin , 

I have attached your test program using slightly longer strings, 5000 or so bytes 

We can see just how much that changes the results as to which is the fastest algorithm. 

The greatest overhead in all the examples would seem to be the number of actual string copies needed to complete the task 
For the larger strings, and the overhead of the interpreter for the shorter strings 

On longer string using fast unsafe the regex methods seem to be the fastest methods out of the box. 

So I guess when doing this sort of stuff, the real question is how much do we have to do.... 

Fast is relative I guess! 

Thank You 
Brian G 


From: "Brian" <brian at westwoodsvcs.com> 
To: "Gambas mailing list" <user at lists.gambas-basic.org> 
Sent: Tuesday, November 10, 2020 8:11:02 AM 
Subject: [Gambas-user] trimming extra spaces from within a string. 

The split and join method was the forth version of doing the space removal in my example, and constantly came out fastest non mashed('c' ized) version of doing it, 
but it does indeed require a lot of memory for large conversion, as does fixstring example 

Thank You 
Brian G 


From: "Gambas mailing list" <user at lists.gambas-basic.org> 
To: "Gambas mailing list" <user at lists.gambas-basic.org> 
Cc: "Linus" <olivier.cruilles at yahoo.fr> 
Sent: Tuesday, November 10, 2020 7:47:32 AM 
Subject: Re: [Gambas-user] trimming extra spaces from within a string. 

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 < [ mailto:rwe-sse at osnanet.de | rwe-sse at osnanet.de ] > a écrit : 

Am 10.11.20 um 12:28 schrieb Christof Thalhofer: 

BQ_BEGIN
Am 10.11.20 um 11:56 schrieb Rolf-Werner Eilert: 

BQ_BEGIN
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. 

BQ_END

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. 


BQ_BEGIN
Alles Gute 

BQ_END

Dir auch :) 

Rolf 

----[ [ http://gambaswiki.org/wiki/doc/netiquette | http://gambaswiki.org/wiki/doc/netiquette ] ]---- 

BQ_END




----[ 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/e12a8ced/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sample-trim-faster-0.0.3.tar.gz
Type: application/x-compressed-tar
Size: 12925 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20201110/e12a8ced/attachment-0001.bin>


More information about the User mailing list