in reply to Re^4: Replace consecutive whitespaces with single whitespace
in thread Replace consecutive whitespaces with single whitespace

You do not copy the string on each single space. If you did then the performance of the substitution would scale like O(n*n), which it does not.

As your benchmark shows, the overhead for the operation is less than a factor of 2. This is extremely unlikely to be a make or break performance issue. There are plenty of other operations you are likely to do with the string that have an even larger overhead. (For example reading it in or printing it.)

Unless performance has proven to be an issue and this is where performance was lost, I remain unconcerned.

  • Comment on Re^5: Replace consecutive whitespaces with single whitespace