Michael Matz wrote:
Hi,
On Thu, 24 Apr 2008, Josef Reidinger wrote:
So I implement it (code of it in test file which I attach). Speed improve is really significant.
Well, nice, but it doesn't do what it's supposed to. You probably want to check some results manually. In particular:
while (string::npos != (loc = sData.find(sFrom, loc))) { sNew.append(sData,oldLoc,loc);
The third argument to append is a length, not an offset.
sNew.append(sTo); loc += toLen; oldLoc = loc; if (loc >= sNew.length()) break;
Get rid of this if and break. It's meanwhile wrong I think.
Ciao, Michael.
Yes, you are right and also one more bug in code (I add toLen, but need frLen). So now after fix results is not so exciting. Conclusion is, that new gsub is better then old and replace_all is better then new_gsub except for longer 'to' string. (but if you need new string and not replacing in-place then new gsub is better). Fixed code of tests and new gsub is attached. same size of replacing strings: new gsub user time: 570 system time: 0 jano replace_all user time: 554 system time: 1 old gsub replace_all user time: 629 system time: 1 to is bigger: new gsub user time: 794 system time: 2 jano replace_all user time: 861 system time: 2 old gsub replace_all user time: 838 system time: 1 from is bigger: new gsub user time: 404 system time: 0 jano replace_all user time: 353 system time: 2 old gsub replace_all user time: 417 system time: 2