Z
zexpe
I have an extremely cpu/data intensive piece of code that makes heavy
use of the following function:
void convertToDouble(const std::string& in, double& out)
{
out = atof(in.c_str());
}
I would really like to get away from using any old C-style functions.
So, I modified the above function to make it follow the C++ convention:
void convertToDouble(const std::string& in, double& out)
{
std::stringstream ss(in);
ss >> out;
}
However, my test code that previously took 30s to run, now takes 45s
(linux gcc 4.0.2 with -03 option). That's a heavy price to pay for
adopting the C++ convention. So, my question is... Is there an
*efficient* way to convert a string to a number (e.g. double) without
requiring the use of old C libraries?
use of the following function:
void convertToDouble(const std::string& in, double& out)
{
out = atof(in.c_str());
}
I would really like to get away from using any old C-style functions.
So, I modified the above function to make it follow the C++ convention:
void convertToDouble(const std::string& in, double& out)
{
std::stringstream ss(in);
ss >> out;
}
However, my test code that previously took 30s to run, now takes 45s
(linux gcc 4.0.2 with -03 option). That's a heavy price to pay for
adopting the C++ convention. So, my question is... Is there an
*efficient* way to convert a string to a number (e.g. double) without
requiring the use of old C libraries?