G
GGG
I have a situation where at tool is passing me a large array of
strings that I need to process in a particular type of data. Each item
in the array gets to me as a pair of std::strings, basically, one
string represents the data, one string represents the data type.
Here's a quick example of what it sort of looks like
string data[4] = { "0.0000002342", "12.00234", "42", "5" };
string types[4] = { "EF", "EF", "I", "I" }; //EF is 64 bit float,
I is 32 bit int
So element 0 of data matches with element 0 of types. i.e. types[0]
defines what type of data data[0] is.
This example is simple, however speed is going to be crucial as I need
to process a thousands of these in very short order. So I am looking
at ways make this work as fast as possible. I can't change the way the
data is being passed to me. I'm stuck with 2 std:string arrays. I'm
thinking a stringstream can work simple for this, but on my current
tests, my target machine can barley process this fast enough...
So I thought I could do something like this(using my dummy data above)
double doubleVal;
int intVal;
for( int i = 0; i < 4; i++) //just hardcode 4 as the size for this
example
{
stringstream tmpStream(data);
if ( types == "EF" )
{
tmpStream >> doubleVal;
//process the double here....
}
else if ( types == "I" )
{
tmpStream >> intVal;
//process the integer here....
}
else
{
cerr << "kerblooy" << endl;
}
}
So basically I am wondering if there is something faster here than
using stringstream, or... is there a way I can declare stringstream
outside of the for loop so its destructor/constructor are not being
called constantly?
Now... I am already working on optimizing the "//process the value
here" part. I've played around with the code an seem to have found
that just this looping part is causing me a little more than have my
CPU usage time.
Any ideas would be cool.
-grant
strings that I need to process in a particular type of data. Each item
in the array gets to me as a pair of std::strings, basically, one
string represents the data, one string represents the data type.
Here's a quick example of what it sort of looks like
string data[4] = { "0.0000002342", "12.00234", "42", "5" };
string types[4] = { "EF", "EF", "I", "I" }; //EF is 64 bit float,
I is 32 bit int
So element 0 of data matches with element 0 of types. i.e. types[0]
defines what type of data data[0] is.
This example is simple, however speed is going to be crucial as I need
to process a thousands of these in very short order. So I am looking
at ways make this work as fast as possible. I can't change the way the
data is being passed to me. I'm stuck with 2 std:string arrays. I'm
thinking a stringstream can work simple for this, but on my current
tests, my target machine can barley process this fast enough...
So I thought I could do something like this(using my dummy data above)
double doubleVal;
int intVal;
for( int i = 0; i < 4; i++) //just hardcode 4 as the size for this
example
{
stringstream tmpStream(data);
if ( types == "EF" )
{
tmpStream >> doubleVal;
//process the double here....
}
else if ( types == "I" )
{
tmpStream >> intVal;
//process the integer here....
}
else
{
cerr << "kerblooy" << endl;
}
}
So basically I am wondering if there is something faster here than
using stringstream, or... is there a way I can declare stringstream
outside of the for loop so its destructor/constructor are not being
called constantly?
Now... I am already working on optimizing the "//process the value
here" part. I've played around with the code an seem to have found
that just this looping part is causing me a little more than have my
CPU usage time.
Any ideas would be cool.
-grant