#1 2016-01-07 15:27:37

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

StringReplace Enhancement

Hi AB,

i found this on the Net
FastStringReplace function from Alexandre Caldas Machado :

http://alexandrecmachado.blogspot.com/2 … elphi.html

http://alexandrecmachado.blogspot.com.a … e-fix.html

It more than 100% (double) faster than Mormot StringReplaceAll although using 2Byte Char. (I made a test with the StringReplace included  StringReplace Test Pgm)

May be you like it...


Rad Studio 12.1 Santorini

Offline

#2 2016-01-07 16:26:04

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: StringReplace Enhancement

@itSDS, Very nice finding and thanks for sharing!

I added to items to the benchmark list, it's ReplaceStr and ReplaceText.
Test results on my computer:

Standard StringReplace(): 0.2180 secs
StringReplace1: 0.1250 secs
StringReplace2: 0.1090 secs
StringReplace3: 1.7630 secs
StringReplace4: 0.0780 secs
FastStringReplace: 0.0310 secs
ReplaceStr: 0.2340 secs
ReplaceText: 0.3430 secs

The winner is: FastStringReplace
------------------------------------------------------------

Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#3 2016-01-07 18:47:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: StringReplace Enhancement

StringReplaceAll() is used in no performance-critical place of mORMot.
So it was not specifically optimized for speed.

But I've made simple speed enhancements.
See http://synopse.info/fossil/info/73f6168422

You may be able to benchmark the new version...
Feedback is welcome!

Offline

#4 2016-01-08 07:02:11

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: StringReplace Enhancement

@ab, Updated the mORMot framework and added StringReplaceAll to the benchmark test, here is the result:

Standard StringReplace(): 0.2340 secs
StringReplace1: 0.1250 secs
StringReplace2: 0.1090 secs
StringReplace3: 1.7160 secs
StringReplace4: 0.0780 secs
FastStringReplace: 0.0470 secs
ReplaceStr: 0.2500 secs
ReplaceText: 0.3430 secs
StringReplaceAll - Implict to UTF8: 0.1250 secs
StringReplaceAll - EXplict to UTF8: 0.0620 secs

The winner is: FastStringReplace
------------------------------------------------------------

New finding: Use of StringToUTF8 can really improve the performance smile


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#5 2016-01-08 17:58:15

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: StringReplace Enhancement

Yes, our optimized version of StringToUTF8/UTF8ToString is faster than the default Delphi RTL conversion, which uses the Windows API...

It is always a good idea to follow the compilation hints to ensure that an explicit conversion is done, using SynCommons.

Offline

Board footer

Powered by FluxBB