Greg said:
zexpe, this, and Walter's point is my point: Your "complaint" is
that stringstreams were too burdensome on an X hour program run,
but frankly although the difference between 1.5 second and 1 second
is 50%, either (a) the time of this one operations does not really
matter on your program or (b) it does matter whereas if it were
me I would look at how to make it better -- imagine you could
get it to 0.50 or less, etc. As Walter pointed out, find out
first and foremost if this is really your bottleneck, then look
at the stragegies Walter and Vladimir mentioned, and any others,
otherwise, we don't understand your premise.
Sorry for confusing you Greg. I think I ended up confusing myself!
The thread started following my attempt to upgrade a piece of C++ code
I'd inherited, as an experiment in "modernising" old code design. These
days we are recommended to use STL containers and algorithms, and
abandon old C-style practises wherever possible. So I ditched the
<cstdlib> atof() in favour of the stringstream technique, but
discovered it made my program run 50% more slowly than before. Clearly
this is too high a price to pay for just "modernisation". Being
aggrieved at having been given bad advice (well, incomplete advice)
about the benefits of the stringstream technique, I posted a message to
find out if there was an equivalent modern C++ to my simple
stringstream approach that did not have a performance penalty. Clearly
there is not.
I had not originally intended to be optimising the code (I *was* happy
with its original execution time and there are more important things to
be done). I was merely modernising the code as a learning exercise for
myself. However, this exercise has highlighted the fact that my program
spends a significant proprotion of its time converting strings to
numbers. I think a lot of these conversions are strictly not necessary
and simply a product of poor overall code design. So, when I have the
time I'll redesign the code, trying to remove as many of these
conversions as possible (I believe the original author wasn't very
mindful of the 1000s of CPU cycles a string to number conversion
consumes). If these conversions remain the most time consuming part of
the program, then I shall investigate the strategies of Walter and
Vladimir.
Thanks for your time everyone.
Ross