I see that you used the stock method on added_data , which should help, avoiding multiple redistributions of the row as it grows.
You should also use the += line operator, if possible:
added_data += data;
I think the above should save some significant time by avoiding unnecessary copies of back and forth added_data in the timeline when doing catenation.
This += operator is a simpler version of the string::append method, it just copies data directly at the end of added_data . Since you made a reserve, this operation should be very fast (almost equivalent to strcpy).
But why does all this happen when you are already using stringstream to process input? Have it all there to get started!
The stringstream class is really not very efficient.
You can look at the stringstream class for more information on how to use it if necessary, but your decision to use a string since the buffer seems to avoid the class speed problem.
In any case, avoid trying to override the critical speed code in pure C unless you really know what you are doing. Some other SO posts support the idea of ββthis, but I think it's best (read safer) to rely on the standard library as much as possible, which will improve over time, and take care of many cases with angles that you (or I) do not I would have thought. If your input format is set in stone, you can start thinking about going that route, but otherwise itβs premature optimization.
source share