To continue on what was asked in https://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21980883.html
I now want to pose a completely different challenge here. What I want is everyone to post a function EXACTLY like the StringReplace function in Delphi. Thus, your code must be something like this:
type TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
onst S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string;
where [Yourname] is replaced by your name, of course. :-)
Now, the challenge is to write a version of this function which is (at least) twice as fast as the Delphi version. (I will test it with Delphi 2006 and will be measuring both the time required to get the result as the number of clockcycles.
Measurements will be done by using a huge file with text. This file will be \Borland\Delphi 2006\source\Win32\rtl\win|
s for Delphi 2006 which happens to be 1.21 megabytes in size. Thus quite large. The file will be read into a string and then passed to the StringReplace functions. The text which will be replaced will be chosen from a list with words, varying in length from 1 character to 20 characters or maybe even a bit more. The strings that they will be replaced with might have the same length or are either bigger or smaller. I will also do one run replacing a word that's not part of this sourcefile. (Which should result in no changes...)
I will have to write a simple console application which will run all the tests, which I will share here. Once that is done, I too will try to write a fast solution... :-)
There will be points for every solution which is twice as fast as the Delphi version. The fastest one will receive 100 points and will be accepted as answer. The second place will be rewarded with 75 points. third-fastest solution will receive 50 points and all other solutions will receive 20 points, if they are fast enough. This Q will be closed when there are 20 fast solutions here or when there haven't been any new solutions for about three weeks. Points will be divided over the top-20.
Feel free to provide as many solutions as you like. Just be clear if something is a new solution or a fix on an existing one.